@@ -48,7 +48,7 @@ |
||
48 | 48 | * Initialization to get controller variable |
49 | 49 | * |
50 | 50 | * @param array $rules Array of rules for permissions. |
51 | -* @return string '0' if user / group doesn't have permission, 1 if has permission |
|
51 | +* @return null|boolean '0' if user / group doesn't have permission, 1 if has permission |
|
52 | 52 | */ |
53 | 53 | public function allow ($rules) { |
54 | 54 | $user_id = $this->session->read('Auth.User.id'); |
@@ -36,13 +36,13 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @param string $event The event to use. |
38 | 38 | */ |
39 | - public function initialize(array $config) |
|
40 | - { |
|
41 | - parent::initialize($config); |
|
39 | + public function initialize(array $config) |
|
40 | + { |
|
41 | + parent::initialize($config); |
|
42 | 42 | |
43 | - $this->controller = $this->_registry->getController(); |
|
44 | - $this->session = $this->controller->request->session(); |
|
45 | - } |
|
43 | + $this->controller = $this->_registry->getController(); |
|
44 | + $this->session = $this->controller->request->session(); |
|
45 | + } |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Initialization to get controller variable |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | * @param array $rules Array of rules for permissions. |
51 | 51 | * @return string '0' if user / group doesn't have permission, 1 if has permission |
52 | 52 | */ |
53 | - public function allow ($rules) { |
|
54 | - $user_id = $this->session->read('Auth.User.id'); |
|
53 | + public function allow ($rules) { |
|
54 | + $user_id = $this->session->read('Auth.User.id'); |
|
55 | 55 | |
56 | 56 | $actions = array(); |
57 | 57 | $bool = true; |
@@ -66,20 +66,20 @@ discard block |
||
66 | 66 | foreach($rules as $key => $value){ |
67 | 67 | switch($key){ |
68 | 68 | case "user_type": |
69 | - $userType = $value; |
|
70 | - break; |
|
71 | - case "redirect": |
|
72 | - $redirect = $value; |
|
73 | - break; |
|
74 | - case "action": |
|
75 | - $action = $value; |
|
76 | - break; |
|
77 | - case "controller": |
|
78 | - $controller = $value; |
|
79 | - break; |
|
80 | - case "message": |
|
81 | - $message = $value; |
|
82 | - break; |
|
69 | + $userType = $value; |
|
70 | + break; |
|
71 | + case "redirect": |
|
72 | + $redirect = $value; |
|
73 | + break; |
|
74 | + case "action": |
|
75 | + $action = $value; |
|
76 | + break; |
|
77 | + case "controller": |
|
78 | + $controller = $value; |
|
79 | + break; |
|
80 | + case "message": |
|
81 | + $message = $value; |
|
82 | + break; |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
@@ -140,5 +140,5 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | return $bool; |
143 | - } |
|
143 | + } |
|
144 | 144 | } |
145 | 145 | \ No newline at end of file |
@@ -50,21 +50,21 @@ discard block |
||
50 | 50 | * @param array $rules Array of rules for permissions. |
51 | 51 | * @return string '0' if user / group doesn't have permission, 1 if has permission |
52 | 52 | */ |
53 | - public function allow ($rules) { |
|
53 | + public function allow($rules) { |
|
54 | 54 | $user_id = $this->session->read('Auth.User.id'); |
55 | 55 | |
56 | - $actions = array(); |
|
57 | - $bool = true; |
|
58 | - $redirect = ''; |
|
59 | - $params = ''; |
|
56 | + $actions = array(); |
|
57 | + $bool = true; |
|
58 | + $redirect = ''; |
|
59 | + $params = ''; |
|
60 | 60 | $controller = ''; |
61 | - $message = ''; |
|
62 | - $userType = ''; |
|
63 | - $find = 0; |
|
61 | + $message = ''; |
|
62 | + $userType = ''; |
|
63 | + $find = 0; |
|
64 | 64 | |
65 | 65 | //setting default options |
66 | - foreach($rules as $key => $value){ |
|
67 | - switch($key){ |
|
66 | + foreach ($rules as $key => $value) { |
|
67 | + switch ($key) { |
|
68 | 68 | case "user_type": |
69 | 69 | $userType = $value; |
70 | 70 | break; |
@@ -84,33 +84,33 @@ discard block |
||
84 | 84 | } |
85 | 85 | |
86 | 86 | //push into array group actions |
87 | - foreach($rules['groups'] as $key => $value){ |
|
88 | - if($key == $userType){ |
|
89 | - foreach($value as $v){ |
|
87 | + foreach ($rules['groups'] as $key => $value) { |
|
88 | + if ($key == $userType) { |
|
89 | + foreach ($value as $v) { |
|
90 | 90 | array_push($actions, $v); |
91 | 91 | } |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | - if(!isset($userId)){ |
|
95 | + if (!isset($userId)) { |
|
96 | 96 | $userType = 'guest'; |
97 | 97 | } |
98 | 98 | |
99 | - if(isset($rules['groups'])){ |
|
100 | - foreach($rules['groups'] as $key => $value){ |
|
101 | - if($key == $userType){ |
|
102 | - if(!in_array('*', $actions)){ |
|
103 | - if(!in_array($action, $actions)){ |
|
99 | + if (isset($rules['groups'])) { |
|
100 | + foreach ($rules['groups'] as $key => $value) { |
|
101 | + if ($key == $userType) { |
|
102 | + if (!in_array('*', $actions)) { |
|
103 | + if (!in_array($action, $actions)) { |
|
104 | 104 | $find = 1; |
105 | - if($redirect != ''){ |
|
106 | - if($message != ''){ |
|
105 | + if ($redirect != '') { |
|
106 | + if ($message != '') { |
|
107 | 107 | $this->Flash->set($message); |
108 | 108 | } |
109 | 109 | |
110 | 110 | header("Location: " . $redirect); |
111 | 111 | exit; |
112 | 112 | } |
113 | - else{ |
|
113 | + else { |
|
114 | 114 | $bool = false; |
115 | 115 | } |
116 | 116 | } |
@@ -119,19 +119,19 @@ discard block |
||
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
122 | - if(($find == 0) && (isset($rules['views']))){ |
|
123 | - foreach($rules['views'] as $key => $value){ |
|
124 | - if($key == $action){ |
|
125 | - if(!$this->controller->$value()){ |
|
126 | - if($redirect != ''){ |
|
127 | - if($message != ''){ |
|
122 | + if (($find == 0) && (isset($rules['views']))) { |
|
123 | + foreach ($rules['views'] as $key => $value) { |
|
124 | + if ($key == $action) { |
|
125 | + if (!$this->controller->$value()) { |
|
126 | + if ($redirect != '') { |
|
127 | + if ($message != '') { |
|
128 | 128 | $this->Flash->set($message); |
129 | 129 | } |
130 | 130 | |
131 | 131 | header("Location: " . $redirect); |
132 | 132 | exit; |
133 | 133 | } |
134 | - else{ |
|
134 | + else { |
|
135 | 135 | $bool = false; |
136 | 136 | } |
137 | 137 | } |
@@ -109,8 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | header("Location: " . $redirect); |
111 | 111 | exit; |
112 | - } |
|
113 | - else{ |
|
112 | + } else{ |
|
114 | 113 | $bool = false; |
115 | 114 | } |
116 | 115 | } |
@@ -130,8 +129,7 @@ discard block |
||
130 | 129 | |
131 | 130 | header("Location: " . $redirect); |
132 | 131 | exit; |
133 | - } |
|
134 | - else{ |
|
132 | + } else{ |
|
135 | 133 | $bool = false; |
136 | 134 | } |
137 | 135 | } |