| @@ 20-77 (lines=58) @@ | ||
| 17 | ||
| 18 | use Zend\View\Helper\AbstractHelper; |
|
| 19 | ||
| 20 | class Isallowed extends AbstractHelper |
|
| 21 | { |
|
| 22 | /** |
|
| 23 | * @var AuthenticationService |
|
| 24 | */ |
|
| 25 | protected $authService; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * __invoke |
|
| 29 | * |
|
| 30 | * @access public |
|
| 31 | * @return \ZfcUser\Entity\UserInterface |
|
| 32 | */ |
|
| 33 | public function __invoke( $resource ) |
|
| 34 | { |
|
| 35 | /** |
|
| 36 | * @var Zend\Permissions\Acl\Acl $acl |
|
| 37 | **/ |
|
| 38 | $acl = $this->view->navigation()->getAcl(); |
|
| 39 | if (empty($resource) || !$acl->hasResource($resource) ) { |
|
| 40 | return true; |
|
| 41 | } |
|
| 42 | /** |
|
| 43 | * @var \Admin\Entity\User $user |
|
| 44 | **/ |
|
| 45 | $user = $this->view->zfcUserIdentity(); // ->getIdentity(); |
|
| 46 | if ($user) { // ($this->getAuthService()->hasIdentity()) { |
|
| 47 | //$user = $this->getAuthService()->getIdentity(); |
|
| 48 | $role = $user->getAclrole(); |
|
| 49 | } else { |
|
| 50 | $role = 'public'; |
|
| 51 | } |
|
| 52 | return ( $acl->isAllowed($role, $resource) ); |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * Get authService. |
|
| 57 | * |
|
| 58 | * @return AuthenticationService |
|
| 59 | */ |
|
| 60 | public function getAuthService() |
|
| 61 | { |
|
| 62 | return $this->authService; |
|
| 63 | } |
|
| 64 | ||
| 65 | /** |
|
| 66 | * Set authService. |
|
| 67 | * |
|
| 68 | * @param AuthenticationService $authService |
|
| 69 | * @return \ZfcUser\View\Helper\ZfcUserIdentity |
|
| 70 | */ |
|
| 71 | public function setAuthService(AuthenticationService $authService) |
|
| 72 | { |
|
| 73 | $this->authService = $authService; |
|
| 74 | return $this; |
|
| 75 | } |
|
| 76 | ||
| 77 | } |
|
| @@ 20-77 (lines=58) @@ | ||
| 17 | ||
| 18 | use Zend\View\Helper\AbstractHelper; |
|
| 19 | ||
| 20 | class Isdenied extends AbstractHelper |
|
| 21 | { |
|
| 22 | /** |
|
| 23 | * @var AuthenticationService |
|
| 24 | */ |
|
| 25 | protected $authService; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * __invoke |
|
| 29 | * |
|
| 30 | * @access public |
|
| 31 | * @return \ZfcUser\Entity\UserInterface |
|
| 32 | */ |
|
| 33 | public function __invoke( $resource ) |
|
| 34 | { |
|
| 35 | /** |
|
| 36 | * @var \Zend\Permissions\Acl\Acl $acl |
|
| 37 | **/ |
|
| 38 | $acl = $this->view->navigation()->getAcl(); |
|
| 39 | if (empty($resource) || !$acl->hasResource($resource) ) { |
|
| 40 | return true; |
|
| 41 | } |
|
| 42 | /** |
|
| 43 | * @var \Admin\Entity\User $user |
|
| 44 | **/ |
|
| 45 | $user = $this->view->zfcUserIdentity(); // ->getIdentity(); |
|
| 46 | if ($user) { // ($this->getAuthService()->hasIdentity()) { |
|
| 47 | //$user = $this->getAuthService()->getIdentity(); |
|
| 48 | $role = $user->getAclrole(); |
|
| 49 | } else { |
|
| 50 | $role = 'public'; |
|
| 51 | } |
|
| 52 | return ( !$acl->isAllowed($role, $resource) ); |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * Get authService. |
|
| 57 | * |
|
| 58 | * @return AuthenticationService |
|
| 59 | */ |
|
| 60 | public function getAuthService() |
|
| 61 | { |
|
| 62 | return $this->authService; |
|
| 63 | } |
|
| 64 | ||
| 65 | /** |
|
| 66 | * Set authService. |
|
| 67 | * |
|
| 68 | * @param AuthenticationService $authService |
|
| 69 | * @return \ZfcUser\View\Helper\ZfcUserIdentity |
|
| 70 | */ |
|
| 71 | public function setAuthService(AuthenticationService $authService) |
|
| 72 | { |
|
| 73 | $this->authService = $authService; |
|
| 74 | return $this; |
|
| 75 | } |
|
| 76 | ||
| 77 | } |
|