This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
/
AppController.php
71 lines (57 loc) · 1.96 KB
/
AppController.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
<?php
namespace App\Controller;
use Cake\Controller\Controller;
use Cake\Event\Event;
use Cake\I18n\Time;
use Cake\Core\Configure;
use \Ceeram\Blame\Controller\BlameTrait;
class AppController extends Controller {
use BlameTrait;
var $CurrentUser = null;
public function initialize() {
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authorize' => ['Controller'],
'loginRedirect' => [
'controller' => 'Characters',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'Users',
'action' => 'login'
]
]);
$this->loadComponent('Cookie');
$this->loadComponent('Slack', [
'webhook_url' => Configure::read('Slack.webhook_url'),
'enabled' => Configure::read('Slack.enabled')
]);
Time::$defaultLocale = 'en-GB';
}
public function isAuthorized($user) {
if (isset($user['role']) && $user['role'] === 'admin') {
return true;
}
return false;
}
public function beforeFilter(Event $event) {
$this->Auth->allow(['view', 'display']);
$this->loadModel('Users');
$cookie = $this->Cookie->read('rememberMe');
if (is_array($cookie) && !$this->Auth->User()) {
if ($this->Users->checkLogin($cookie['username'], $cookie['password'])) {
$this->Auth->setUser($this->Users->data->toArray());
}
}
if ($this->Auth->user()) {
$this->CurrentUser = $this->Users->get($this->Auth->User('id'));
} else {
$this->CurrentUser = new \App\Model\Entity\User();
}
$this->set('debug', Configure::read('debug'));
$this->set('user', $this->CurrentUser);
$this->set('version', Configure::read('rpgApp.version'));
}
}