@@ -51,21 +51,21 @@ discard block |
||
| 51 | 51 | * @param array $rules Array of rules for permissions. |
| 52 | 52 | * @return string '0' if user / group doesn't have permission, 1 if has permission |
| 53 | 53 | */ |
| 54 | - public function allow ($rules) { |
|
| 54 | + public function allow($rules) { |
|
| 55 | 55 | $user_id = $this->session->read('Auth.User.id'); |
| 56 | 56 | |
| 57 | - $actions = array(); |
|
| 58 | - $bool = '1'; |
|
| 59 | - $redirect = ''; |
|
| 60 | - $params = ''; |
|
| 57 | + $actions = array(); |
|
| 58 | + $bool = '1'; |
|
| 59 | + $redirect = ''; |
|
| 60 | + $params = ''; |
|
| 61 | 61 | $controller = ''; |
| 62 | - $message = ''; |
|
| 63 | - $userType = ''; |
|
| 64 | - $find = 0; |
|
| 62 | + $message = ''; |
|
| 63 | + $userType = ''; |
|
| 64 | + $find = 0; |
|
| 65 | 65 | |
| 66 | 66 | //setting default options |
| 67 | - foreach($rules as $key => $value){ |
|
| 68 | - switch($key){ |
|
| 67 | + foreach ($rules as $key => $value) { |
|
| 68 | + switch ($key) { |
|
| 69 | 69 | case "user_type": |
| 70 | 70 | $userType = $value; |
| 71 | 71 | break; |
@@ -85,33 +85,33 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | //push into array group actions |
| 88 | - foreach($rules['groups'] as $key => $value){ |
|
| 89 | - if($key == $userType){ |
|
| 90 | - foreach($value as $v){ |
|
| 88 | + foreach ($rules['groups'] as $key => $value) { |
|
| 89 | + if ($key == $userType) { |
|
| 90 | + foreach ($value as $v) { |
|
| 91 | 91 | array_push($actions, $v); |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if(!isset($userId)){ |
|
| 96 | + if (!isset($userId)) { |
|
| 97 | 97 | $userType = 'guest'; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if(isset($rules['groups'])){ |
|
| 101 | - foreach($rules['groups'] as $key => $value){ |
|
| 102 | - if($key == $userType){ |
|
| 103 | - if(!in_array('*', $actions)){ |
|
| 104 | - if(!in_array($action, $actions)){ |
|
| 100 | + if (isset($rules['groups'])) { |
|
| 101 | + foreach ($rules['groups'] as $key => $value) { |
|
| 102 | + if ($key == $userType) { |
|
| 103 | + if (!in_array('*', $actions)) { |
|
| 104 | + if (!in_array($action, $actions)) { |
|
| 105 | 105 | $find = 1; |
| 106 | - if($redirect != ''){ |
|
| 107 | - if($message != ''){ |
|
| 106 | + if ($redirect != '') { |
|
| 107 | + if ($message != '') { |
|
| 108 | 108 | $this->Flash->set($message); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | header("Location: " . $redirect); |
| 112 | 112 | exit; |
| 113 | 113 | } |
| 114 | - else{ |
|
| 114 | + else { |
|
| 115 | 115 | $bool = '0'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -120,19 +120,19 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - if(($find == 0) && (isset($rules['views']))){ |
|
| 124 | - foreach($rules['views'] as $key => $value){ |
|
| 125 | - if($key == $action){ |
|
| 126 | - if(!$this->controller->$value()){ |
|
| 127 | - if($redirect != ''){ |
|
| 128 | - if($message != ''){ |
|
| 123 | + if (($find == 0) && (isset($rules['views']))) { |
|
| 124 | + foreach ($rules['views'] as $key => $value) { |
|
| 125 | + if ($key == $action) { |
|
| 126 | + if (!$this->controller->$value()) { |
|
| 127 | + if ($redirect != '') { |
|
| 128 | + if ($message != '') { |
|
| 129 | 129 | $this->Flash->set($message); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | header("Location: " . $redirect); |
| 133 | 133 | exit; |
| 134 | 134 | } |
| 135 | - else{ |
|
| 135 | + else { |
|
| 136 | 136 | $bool = '0'; |
| 137 | 137 | } |
| 138 | 138 | } |