Created
January 28, 2015 19:54
-
-
Save rfos/63bef38df8b9b0168b66 to your computer and use it in GitHub Desktop.
Chamando o AuthComponent
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
class AppController extends Controller { | |
public $components = array( | |
'Acl', | |
'Session', | |
'Email', | |
'DebugKit.Toolbar', | |
'Auth' => array( | |
'loginRedirect' => array( | |
'controller' => 'users', | |
'action' => 'index' | |
), | |
'logoutRedirect' => array( | |
'controller' => 'pages', | |
'action' => 'index' | |
), | |
'authenticate' => array( | |
'Form' => array( | |
'scope' => array('ativacao' => '1'), | |
'passwordHasher' => 'Blowfish' | |
) | |
) | |
) | |
); | |
public function beforeFilter() { | |
// Definindo o algorítmo de hash para a senha (OPCIONAL) | |
$this->Auth->authenticate = array('Blowfish' => array( | |
'userModel' => 'User', | |
)); | |
// Informando controller/action para login | |
$this->Auth->loginAction = array( | |
'controller' => 'users', | |
'action' => 'login' | |
); | |
// controller/action após realizar o login | |
$this->Auth->loginRedirect = array( | |
'controller' => 'videos', | |
'action' => 'index' | |
); | |
// controller/action após realizar o logout | |
$this->Auth->logoutRedirect = array( | |
'controller' => 'pages', | |
'action' => 'index' | |
); | |
// Actions habilitadas para usuários não logados | |
$this->Auth->allow(''); | |
// Definindo uma mensagem de erro do ACL | |
$this->Auth->authError = 'Suas permissões não concedem acesso ao recurso solicitado.'; | |
if ($this->Auth->user()) { | |
if( !$this->isAuthorized() ) { | |
$this->Session->setFlash($this->Auth->authError); | |
$this->redirect($this->Auth->redirectUrl()); | |
} | |
$this->Auth->allow(); | |
} | |
parent::beforeFilter(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment