I want to add some basic authentication to my app. So I mostly followed the cookbook tutorial but I want to sign in with my email instead of a username. So I wrote following lines:
AppController.php
public $components = array(
'Auth' => array(
'authentication' => array(
AuthComponent::ALL => array(
'fields' => array('username' => 'email')
)
)
)
);
UsersController.php
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirectUrl());
}
$this->Session->setFlash(__('Invalid email/password combination'));
}
}
login.ctp
<?php
echo $this->Form->create('User');
echo $this->Form->input('email');
echo $this->Form->input('password');
echo $this->Form->end(__('Login'));
?>
User.php
public function beforeSave($options = array()) {
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
return true;
}
I created a user before but I am not able to login. What am I doing wrong? I am getting crazy...
According to the CakePHP book the array should look like this: