-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacl.php
58 lines (51 loc) · 1.58 KB
/
acl.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
<?php
class ACL {
private static $perms;
private static $role_field;
public function __construct() {
$this->role_field = 'role_id';
$this->perms[0]['home']['index'] = true;
$this->perms[0]['home']['about'] = true;
$this->perms[1]['user']['dashboard'] = true;
$this->perms[1]['user']['edit'] = true;
$this->perms[1]['user']['show'] = true;
$this->perms[2]['admin']['dashboard'] = true;
$this->perms[3]['admin']['settings'] = true;
}
public function auth(){
$CI =& get_instance();
if (!isset($CI->session)){
$CI->load->library('session');
}
if (!isset($CI->router)){
$CI->load->library('router');
}
$class = $CI->router->fetch_class();
$method = $CI->router->fetch_method();
$is_ruled = false;
foreach ($this->perms as $role){
if (isset($role[$class][$method])){
$is_ruled = true;
}
}
if (!$is_ruled){
return;
}
if ($CI->session->userdata($this->role_field)){
if ($this->perms[$CI->session->userdata($this->role_field)][$class][$method]){
return true;
}
else{
$CI->error->show(403);
}
}
else{
if ($this->perms[0][$class][$method]){
return true;
}
else{
$CI->error->show(403);
}
}
}
}