-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_controller.php
209 lines (185 loc) · 4.81 KB
/
app_controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
/**
* Application controller
*
* This file is the base controller of all other controllers
*
* PHP version 5
*
* @category Controllers
* @package Croogo
* @version 1.0
* @author Fahad Ibnay Heylaal <contact@fahad19.com>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @link http://www.croogo.org
*/
class AppController extends Controller {
/**
* Components
*
* @var array
* @access public
*/
public $components = array(
'Croogo',
'Security',
'Acl',
'Auth',
'Acl.AclFilter',
'Session',
'RequestHandler',
'Cookie'
);
/**
* Helpers
*
* @var array
* @access public
*/
public $helpers = array(
'Html',
'Form',
'Session',
'Text',
'Js',
'Time',
'Layout',
'Custom',
);
/**
* Models
*
* @var array
* @access public
*/
public $uses = array(
'Block',
'Link',
'Setting',
'Node',
);
var $mobile = false;
/**
* Cache pagination results
*
* @var boolean
* @access public
*/
public $usePaginationCache = true;
/**
* View
*
* @var string
* @access public
*/
public $view = 'Theme';
/**
* Theme
*
* @var string
* @access public
*/
public $theme;
/**
* Constructor
*
* @access public
*/
public function __construct() {
Croogo::applyHookProperties('Hook.controller_properties');
parent::__construct();
if ($this->name == 'CakeError') {
$this->_set(Router::getPaths());
$this->params = Router::getParams();
$this->constructClasses();
$this->Component->initialize($this);
$this->beforeFilter();
$this->Component->triggerCallback('startup', $this);
}
}
/**
* beforeFilter
*
* @return void
*/
public function beforeFilter() {
/*
$user = $this->Auth->User();
if(empty($user)){
if($this->RequestHandler->isMobile()){// && $this->request->data('token') && $this->request->data('hash')) {
//$this->mobile = $this->User->authenticateMobile($this->request->data('hash'),$this->request->data('token'));
$response = array(
'logged' => true,
'name' => 'derek',
'email' => 'email'
);
echo json_encode($response);
exit();
}
}
*/
if ($this->RequestHandler->ext == 'json' && $this->action !='login')
{
$this->RequestHandler->setContent('json', 'application/json');
//Prevent debug output that'll corrupt your json data
Configure::write('debug', 0);
App::import('Model','User');
$this->User = new User;
$token = $_POST['token'];
$mobileuser = $this->User->authenticateMobile($token);
$this->Auth->login($mobileuser);
}
$this->Auth->authenticate = ClassRegistry::init('User');
$this->AclFilter->auth();
$this->RequestHandler->setContent('json', 'text/x-json');
$this->Security->blackHoleCallback = '__securityError';
if (isset($this->params['admin']) && $this->name != 'CakeError') {
$this->layout = 'admin';
}
if ($this->RequestHandler->isAjax()) {
$this->layout = 'ajax';
}
if (Configure::read('Site.theme') && !isset($this->params['admin'])) {
$this->theme = Configure::read('Site.theme');
} elseif (Configure::read('Site.admin_theme') && isset($this->params['admin'])) {
$this->theme = Configure::read('Site.admin_theme');
}
if (!isset($this->params['admin']) &&
Configure::read('Site.status') == 0) {
$this->layout = 'maintenance';
$this->set('title_for_layout', __('Site down for maintenance', true));
$this->render('../elements/blank');
}
if (isset($this->params['locale'])) {
Configure::write('Config.language', $this->params['locale']);
}
/*
// This property will hold a value if the user is viewing the mobile version of our app.
$this->mobile = !empty($this->params['mobile']) ? true : false;
// Redirect if mobile a mobile device, not yet in the mobile site, and doesn't have the cookie yet.
$visited = null;
$visited = $this->Cookie->read('Info.Visited');
// Not on the mobile site, is a mobile device, and a first-time visitor
if (!$visited) {
$this->Cookie->write('Info.Visited', 1);
$this->params['mobile'] = true;
if (!$this->mobile && $this->RequestHandler->isMobile()) {
$this->redirect( array('controller' => 'items', 'action' => 'add', 'mobile'=>true));
}
}
$this->set('mobile', $this->mobile);
if ($this->mobile) {
$this->layout = 'mobile';
}
*/
}
/**
* blackHoleCallback for SecurityComponent
*
* @return void
*/
public function __securityError() {
$this->cakeError('securityError');
}
}
?>