Hi.
I am creating a new project from cero, and the auth component is not working properly, i did every thing as in the tutorial but once the user is logged in , he is being redirected once again to the login form.
I am using version 3.0,
Apache/2.4.16 (Win32) OpenSSL/1.0.1p PHP/5.5.29
PHP Version 5.5.29
The session its is created in the folder cakephp/tmp/sessions.
the file is in… but the user is being redirected to the login page.
This is my configuration.
In AppController i got this.
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
//'authorize' => ['Controller'],
'unauthorizedRedirect' => false,
'loginRedirect' => [
'controller' => 'Notas', // @todo Mi Controller segun PROYECTO a modo de demo
'action' => 'menu'
],
'logoutRedirect' => [
'controller' => 'Estados', // @todo Mi Controller segun PROYECTO
'action' => 'index'
],
'loginAction' => [
'controller' => 'Users', // @todo Mi Controller segun PROYECTO
'action' => 'login'
],
'authenticate' => [
'Form' => [
//'passwordHasher' => 'Blowfish',
'userModel' => 'Users', // @todo Mi TABLA segun DB
'fields' => ['username' => 'username', 'password' => 'password'], // @todo mis campos personalizados segun DB
//'scope' => ['Users.activo' => 'S'] // @todo Filtro para bloquiar ingresos de usuarios
]
],
'authError' => '¿De verdad crees que se le permita ver eso?',
'storage' => 'Session'
]);
//$this->Auth->config('checkAuthIn', 'Controller.initialize');
}
— in the NotasController i Got this
public function initialize()
{
parent::initialize();
//$this->loadComponent('Auth');
//$this->loadComponent('Paginator');
$this->loadComponent('Auth');
$this->viewBuilder()->layout('admin_template');
}
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
$u = $this->Auth->user();
if( $this->isAuthorized( $u ) )
{
$this->Auth->allow();
$this->set('auth_user', $u );
return;
}
//$this->Flash->error("No autorizado");
//$this->redirect( ['action'=>'login', 'controller'=>'users'] );
}
public function isAuthorized( $user = null )
{
if( empty($user) ){
//echo "User is empty";
//die();
return false;
}
$role = '';
if ( isset($user['role']) )
{
$role = $user['role'];
}
if( empty($role) === true )
$role = $this->Auth->User('role');
$role = strtoupper($role);
if( $role == 'ADMIN' )
{
return true;
}
$this->Flash->error("No Authorized");
return parent::isAuthorized($user);
}