I developed an app locally with Cakephp 2.8 over MAMP and testing with Chrome. I implemented users login with Auth component following the manual and a tutorial. Everything worked well, but when I finished the app I tried to login in Safari and Firefox, and it didn't work. I get the authentication error with a wrong password but with the right one, login redirects me to the home page (the index of my Jugadores controller) and the actions protected by Auth can never be accessed, I'm asked to login over and over like the if session is never created. When I deployed my app in a live server, it worked in no browser, this makes me think I'm doing something wrong but I'm can't find what.
Here is the code in my AppController:
<?php
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'jugadores', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'jugadores', 'action' => 'index'),
'authError' => 'You can not access that page.',
'authorize' => array('Controller')
)
);
public function isAuthorized($user) {
return true; //for simplicity. Is it wrong?
}
public function beforeFilter() {
$this->Auth->allow('view','index');
}
}
?>
And my Users controller is:
<?php
App::uses('AppController', 'Controller');
class UsersController extends AppController {
public $components = array('Paginator', 'Flash', 'Session');
public function beforeFilter() {
parent::beforeFilter();
}
public function login() {
if($this->request->is('post')){
if($this->Auth->login()){
return $this->redirect($this->Auth->redirectUrl());
} else {
$this->Flash->set('Wrong user/password.');
}
}
}
public function logout(){
return $this->redirect($this->Auth->logout());
}
}
?>
The login view looks like this:
<div class="users view">
<h2>Login</h2>
<?php
echo $this->Form->create('User');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end('Enter');
?>
</div>
For the users database I followed the Cakephp conventions. Fields: id, username, password, role, created, modified
EDIT: I placed this in the beforeRender function of the AppController:
$this->set('current_user', $this->Auth->user());
And printed it in the layout default.ctp with:
print_r($current_user);
Chrome always prints the logged in user data when testing in local server, but Firefox and Safari only print when requesting an Auth protected action (and takes me to login page). In live server all browsers act the same (logged user data not always appears). So I think in some way Auth is working and creating a session, but not behaving as it should.