Skip to content

Instantly share code, notes, and snippets.

@rfos
Created January 28, 2015 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfos/63bef38df8b9b0168b66 to your computer and use it in GitHub Desktop.
Save rfos/63bef38df8b9b0168b66 to your computer and use it in GitHub Desktop.
Chamando o AuthComponent
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