|
1
|
|
|
<?php |
|
2
|
|
|
namespace App\Controller; |
|
3
|
|
|
|
|
4
|
|
|
use App\I18n\Language; |
|
5
|
|
|
use Cake\Controller\Controller; |
|
6
|
|
|
use Cake\Core\Configure; |
|
7
|
|
|
use Cake\Event\Event; |
|
8
|
|
|
|
|
9
|
|
|
class AppController extends Controller |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Initialization hook method. |
|
14
|
|
|
* |
|
15
|
|
|
* @return void |
|
16
|
|
|
*/ |
|
17
|
|
|
public function initialize() |
|
18
|
|
|
{ |
|
19
|
|
|
parent::initialize(); |
|
20
|
|
|
|
|
21
|
|
|
//Components. |
|
22
|
|
|
$this->loadComponent('Flash'); |
|
23
|
|
|
$this->loadComponent('Cookie'); |
|
24
|
|
|
$this->loadComponent('Acl.Acl'); |
|
25
|
|
|
$this->loadComponent('Maintenance'); |
|
26
|
|
|
$this->loadComponent('CookieLogin'); |
|
27
|
|
|
$this->loadComponent('SessionsActivity'); |
|
28
|
|
|
$this->loadComponent('Auth', [ |
|
29
|
|
|
'className' => 'AclAuth', |
|
30
|
|
|
'allowedActionsForBanned' => [ |
|
31
|
|
|
'Pages' => [ |
|
32
|
|
|
'home' |
|
33
|
|
|
] |
|
34
|
|
|
], |
|
35
|
|
|
'authenticate' => [ |
|
36
|
|
|
'Form', |
|
37
|
|
|
'Xety/Cake3CookieAuth.Cookie' |
|
38
|
|
|
], |
|
39
|
|
|
'flash' => [ |
|
40
|
|
|
'element' => 'error', |
|
41
|
|
|
'key' => 'flash', |
|
42
|
|
|
'params' => [ |
|
43
|
|
|
'class' => 'error' |
|
44
|
|
|
] |
|
45
|
|
|
], |
|
46
|
|
|
'authorize' => [ |
|
47
|
|
|
'Acl.Actions' => [ |
|
48
|
|
|
'actionPath' => 'app/' |
|
49
|
|
|
] |
|
50
|
|
|
], |
|
51
|
|
|
'loginAction' => [ |
|
52
|
|
|
'controller' => 'users', |
|
53
|
|
|
'action' => 'login', |
|
54
|
|
|
'prefix' => false |
|
55
|
|
|
], |
|
56
|
|
|
'unauthorizedRedirect' => [ |
|
57
|
|
|
'controller' => 'pages', |
|
58
|
|
|
'action' => 'home', |
|
59
|
|
|
'prefix' => false |
|
60
|
|
|
], |
|
61
|
|
|
'loginRedirect' => [ |
|
62
|
|
|
'controller' => 'pages', |
|
63
|
|
|
'action' => 'home' |
|
64
|
|
|
], |
|
65
|
|
|
'logoutRedirect' => [ |
|
66
|
|
|
'controller' => 'pages', |
|
67
|
|
|
'action' => 'home' |
|
68
|
|
|
] |
|
69
|
|
|
]); |
|
70
|
|
|
|
|
71
|
|
|
$this->loadComponent('Csrf', [ |
|
72
|
|
|
'secure' => env('HTTPS') ? true : false |
|
73
|
|
|
]); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* beforeFilter handle. |
|
78
|
|
|
* |
|
79
|
|
|
* @param Event $event The beforeFilter event that was fired. |
|
80
|
|
|
* |
|
81
|
|
|
* @return void |
|
82
|
|
|
*/ |
|
83
|
|
|
public function beforeFilter(Event $event) |
|
84
|
|
|
{ |
|
85
|
|
|
$this->loadModel('Settings'); |
|
86
|
|
|
$this->Settings->setSettings(); |
|
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
$this->Auth->config('authError', __('You need to be logged in or you are not authorized to access that location !')); |
|
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
// Define the language |
|
91
|
|
|
$language = new Language($this); |
|
92
|
|
|
$language->setLanguage(); |
|
93
|
|
|
|
|
94
|
|
|
// Set trustProxy to get the original visitor IP |
|
95
|
|
|
$this->request->trustProxy = true; |
|
96
|
|
|
|
|
97
|
|
|
// Cookie Login (Automatically Login) |
|
98
|
|
|
$this->CookieLogin->handle(); |
|
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
// Layouts |
|
101
|
|
|
if (!is_null($this->request->getParam('prefix'))) { |
|
102
|
|
|
$prefix = explode('/', $this->request->getParam('prefix'))[0]; |
|
103
|
|
|
|
|
104
|
|
|
switch ($prefix) { |
|
105
|
|
|
case 'admin': |
|
106
|
|
|
$this->viewBuilder()->layout('admin'); |
|
|
|
|
|
|
107
|
|
|
break; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
// Cookies |
|
112
|
|
|
$allowCookies = $this->Cookie->check('allowCookies'); |
|
113
|
|
|
$this->set(compact('allowCookies')); |
|
114
|
|
|
|
|
115
|
|
|
// Maintenance |
|
116
|
|
|
$this->Maintenance->handle(); |
|
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
// JavaScript Notifications |
|
119
|
|
|
if ($this->request->session()->read('Notification') && !empty($this->request->session()->read('Notification'))) { |
|
|
|
|
|
|
120
|
|
|
$notification = $this->request->session()->read('Notification'); |
|
121
|
|
|
$this->request->session()->delete('Notification'); |
|
122
|
|
|
|
|
123
|
|
|
$this->set(compact('notification')); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* beforeRender hook method. |
|
129
|
|
|
* |
|
130
|
|
|
* @param Event $event The beforeRender event that was fired. |
|
131
|
|
|
* |
|
132
|
|
|
* @return void |
|
133
|
|
|
*/ |
|
134
|
|
|
public function beforeRender(Event $event) |
|
135
|
|
|
{ |
|
136
|
|
|
parent::beforeRender($event); |
|
137
|
|
|
|
|
138
|
|
|
if ($this->components()->has('Auth')) { |
|
139
|
|
|
$builder = $this->viewBuilder(); |
|
140
|
|
|
$builder->helpers([ |
|
|
|
|
|
|
141
|
|
|
'Acl' => $this->Auth->config('authorize')['Acl.Actions'] |
|
|
|
|
|
|
142
|
|
|
]); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.