Skip to content

Instantly share code, notes, and snippets.

@andrebian
Last active December 20, 2015 11:39
Show Gist options
  • Save andrebian/6125302 to your computer and use it in GitHub Desktop.
Save andrebian/6125302 to your computer and use it in GitHub Desktop.
<?php
class AppController extends Controller {
public $components = array('Session', 'Acl', 'Auth');
public function beforeFilter() {
// Mecanismo de autenticação
$this->Auth->authenticate = array('Blowfish' => array(
// Configura o model e os campos
'userModel' => 'Usuario',
'fields' => array(
'username' => 'email',
'password' => 'senha',
),
));
if (!isset($this->request->params['admin'])) {
$this->Auth->allow();
$blackList = array(
'cestaDeCompras', 'minhaConta', 'iniciar', 'meusPedidos'
);
$this->Auth->deny($blackList);
}
$this->Auth->loginAction = array(
'controller' => 'usuarios',
'action' => 'login'
);
if (isset($this->request->params['admin'])) {
if ($this->Auth->user('group_id') == '1') {
$this->Auth->allow();
}
$this->layout = 'admin';
}
// Iremos autorizar controllers e actions
$this->Auth->authorize = array(
'Actions' => array('actionPath' => 'controllers')
);
//definindo a mensagem
$this->Auth->authError = __('<div class="notification msgerror"><div class="alert alert-error"><p>Você precisa realizar o login para acessar a área solicitada.</p></div></div>');
return parent::beforeFilter();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment