-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp_controller.php
executable file
·80 lines (72 loc) · 1.94 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
<?php
class AppController extends Controller
{
var $helpers = array("Html", "Form", "Javascript", "Session", "Time", "Text", "H");
var $components = array("RequestHandler", "DebugKit.Toolbar");
// var $components = array("RequestHandler");
var $beforFilter = array();
var $authorized = array("usr");
function __construct()
{
$this->smtpOptions = array(
"host" => Configure::read("Smtp.host"),
"username" => Configure::read("Smtp.username"),
"password" => Configure::read("Smtp.password"),
"type" => Configure::read("Smtp.type"),
"port" => Configure::read("Smtp.port")
);
parent::__construct();
}
function beforeFilter()
{
// CHECK IF NEED LOGIN
$controllers = Configure::read('base.authorization');
// check if ther this controller name with a key of base.authorization
if (array_key_exists($this->params['controller'], $controllers))
{
// if value of key isn't an array
if (!is_array($controllers[$this->params['controller']]))
{
$controllers[$this->params['controller']] = array($controllers[$this->params['controller']]);
}
foreach ($controllers[$this->params['controller']] as $action)
{
if (("" == $action || $this->params['action'] == $action) && $action != "permission_denied")
{
$this->__login_requeired();
}
}
}
// loop em todos os nomes de filtros e chama os mesmos.
foreach($this->beforFilter as $filter){
$this->$filter();
}
}
function __login_requeired()
{
//
if(!$this->Session->check('user'))
{
$url = "/{$this->params["url"]["url"]}";
$this->Session->write('redirect', str_replace("//", "/", $url));
$this->redirect('/users/login');
}
//
else
{
$user = $this->Session->read('user');
$authorized = false;
foreach ($this->authorized as $group)
{
if (in_array($group, $user['Group']))
{
$authorized = true;
}
}
if(!$authorized){
$this->redirect('/users/permission_denied');
}
}
}
}
?>