Created
May 23, 2011 19:37
-
-
Save eminetto/987396 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
public function init() { | |
//deve chamar o método init da classe pai, sempre | |
parent::init(); | |
$session = Zend_Registry::get('session'); | |
//verifica ACL | |
if(Zend_Registry::isRegistered('acl')) { | |
$request = $this->getRequest(); | |
//pega o nome do modulo, controlador e action | |
$controller = $request->getControllerName(); | |
$module = $request->getModuleName(); | |
$action = $request->getActionName(); | |
//monta o nome do resource e do privilege. exemplo: default_index | |
$resource = $module . '_' . $controller; | |
$privilege = $action; | |
$auth = Zend_Auth::getInstance(); | |
//se o usuário fez login usa a role que está na sessão | |
if($auth->hasIdentity()) { | |
$role = $session->role; | |
$login = $auth->getIdentity(); | |
$this->view->login = $auth->getIdentity(); | |
} | |
else { | |
$role = 'visitante'; | |
} | |
//faz a verificação da permissão | |
$acl = Zend_Registry::get('acl'); | |
if(!$acl->isAllowed($role, $resource, $privilege)) { | |
$session->erro = 'ACL inválida'; | |
$this->_redirect('/admin/admin'); | |
exit; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment