I'm new to cakePHP and I have read their documentation and I'm following their simple authentication example. I've also searched far and wide (including answers on this site) for an answer to my problem.
I'm using cakePHP 2.0 and my UsersController's login function looks like this:
function login() {
if ($this->request->is('post')) {
if ($this->Auth->login(/*$this->request->data*/)) {
$this->redirect($this->Auth->redirect());
}else {
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
}
My AppController looks like this:
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'pages', 'action' => 'display'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'display')
)
);
public function beforeFilter() {
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
}
My User Model:
class User extends AppModel {
public $name = "User";
}
And the login form:
echo $this->Session->flash('auth');
echo $this->Form->create('User', array('action' => 'login'));
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end('Login');
The problem is it doesn't log a user in. When $this->Auth->login() is called without $this->request->data as a parameter nothing is written in the session and the page just refreshes.However when you supply the $this->request->data it works, credentials are written to the session and I'm redirected correctly. However I've noticed that you can 'log in' anyone with $this->Auth->login($this->request->data) even if they are not present in the database. In addition to this, if I enter wrong credentials nothing happens, no flash messages are displayed.
I'm not trying to do anything special, all I want is the ability to log a user in. I have a simple users table with username and password fields and I have followed their example and read their documentation, but still nothing I have tried has worked.
I apologise if I have not supplied all the information needed to provide a response. Any help is greatly appreciated.