I started using the cakephp recently and I created a page from login to my project. The login works perfectly, but is always displaying an invalid user or password.
What can I do to display this message ONLY when login is invalid?
Login function:
public function login() {
if ($this->Auth->login()) {
if($this->Auth->user('role') === 'paciente') {
$this->redirect(array('controller' => 'pacientes', 'action' => 'index'));
}
elseif($this->Auth->user('role') === 'medico') {
$this->redirect(array('controller' => 'medicos', 'action' => 'index'));
}
} else {
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}