| @@ 83-110 (lines=28) @@ | ||
| 80 | * |
|
| 81 | * @throws Exceptions\InvalidArgumentException |
|
| 82 | */ |
|
| 83 | private function checkUser($element) : bool |
|
| 84 | { |
|
| 85 | // Check if element has @Secured\User annotation |
|
| 86 | if ($element->hasAnnotation('Secured\User')) { |
|
| 87 | // Get user annotation |
|
| 88 | $user = $element->getAnnotation('Secured\User'); |
|
| 89 | ||
| 90 | // Annotation is single string |
|
| 91 | if (is_string($user) && in_array($user, ['loggedIn', 'guest'], TRUE)) { |
|
| 92 | // User have to be logged in and is not |
|
| 93 | if ($user === 'loggedIn' && $this->user->isLoggedIn() === FALSE) { |
|
| 94 | return FALSE; |
|
| 95 | ||
| 96 | // User have to be logged out and is logged in |
|
| 97 | } elseif ($user === 'guest' && $this->user->isLoggedIn() === TRUE) { |
|
| 98 | return FALSE; |
|
| 99 | } |
|
| 100 | ||
| 101 | // Annotation have wrong definition |
|
| 102 | } else { |
|
| 103 | throw new Exceptions\InvalidArgumentException('In @Security\User annotation is allowed only one from two strings: \'loggedIn\' & \'guest\''); |
|
| 104 | } |
|
| 105 | ||
| 106 | return TRUE; |
|
| 107 | } |
|
| 108 | ||
| 109 | return TRUE; |
|
| 110 | } |
|
| 111 | ||
| 112 | /** |
|
| 113 | * @param UI\ComponentReflection|UI\MethodReflection|Nette\Reflection\ClassType|Nette\Reflection\Method|\Reflector $element |
|
| @@ 81-108 (lines=28) @@ | ||
| 78 | * |
|
| 79 | * @throws Exceptions\InvalidArgumentException |
|
| 80 | */ |
|
| 81 | private function checkUser(Utils\ArrayHash $element) : bool |
|
| 82 | { |
|
| 83 | // Check if element has user parameter |
|
| 84 | if ($element->offsetExists('user')) { |
|
| 85 | // Get user parameter |
|
| 86 | $user = $element->offsetGet('user'); |
|
| 87 | ||
| 88 | // Parameter is single string |
|
| 89 | if (is_string($user) && in_array($user, ['loggedIn', 'guest'], TRUE)) { |
|
| 90 | // User have to be logged in and is not |
|
| 91 | if ($user === 'loggedIn' && $this->user->isLoggedIn() === FALSE) { |
|
| 92 | return FALSE; |
|
| 93 | ||
| 94 | // User have to be logged out and is logged in |
|
| 95 | } elseif ($user === 'guest' && $this->user->isLoggedIn() === TRUE) { |
|
| 96 | return FALSE; |
|
| 97 | } |
|
| 98 | ||
| 99 | // Parameter have multiple definitions |
|
| 100 | } else { |
|
| 101 | throw new Exceptions\InvalidArgumentException('In parameter \'user\' is allowed only one from two strings: \'loggedIn\' & \'guest\''); |
|
| 102 | } |
|
| 103 | ||
| 104 | return TRUE; |
|
| 105 | } |
|
| 106 | ||
| 107 | return TRUE; |
|
| 108 | } |
|
| 109 | ||
| 110 | /** |
|
| 111 | * @param Utils\ArrayHash $element |
|