Created
November 4, 2012 14:08
-
-
Save eminetto/4012068 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Faz a autorização do usuário para acessar o recurso | |
* @param string $moduleName Nome do módulo sendo acessado | |
* @param string $controllerName Nome do controller | |
* @param string $actionName Nome da ação | |
* @return boolean | |
*/ | |
public function authorize($moduleName, $controllerName, $actionName) | |
{ | |
$auth = new AuthenticationService(); | |
$role = 'visitante'; | |
if ($auth->hasIdentity()) { | |
$session = $this->getServiceManager()->get('Session'); | |
$user = $session->offsetGet('user'); | |
$role = $user->role; | |
} | |
$resource = $controllerName . '.' . $actionName; | |
$acl = $this->getServiceManager()->get('Core\Acl\Builder')->build(); | |
if ($acl->isAllowed($role, $resource)) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment