In my case Auth component not responding properly. when i am login with wrong mail address it shows error but when i am login with right email address but wrong password it does not show error and redirect to authentic inner page.
AppController.php
public $components = array(
'Session',
'Auth' => array(
'authenticate' => array(
'Form' => array(
'fields' => array(
'username' => 'email'
)
),
'loginRedirect' => array(
'controller' => 'users',
'action' => 'index',
)
),
);
UsersController.php
public function login() {
$this->layout = 'login';
if ($this->request->is('post')) {
if ($this->Auth->login($this->data)) {
if (!empty($this->request->data)) {
$access_controll = $this->{$this->modelClass}->find('first', array('conditions'=>array('email'=>$this->request->data['User']['email'])));
if (!empty($access_controll)) {
$role_id = $access_controll['User']['role_id'];
if( ($role_id == 1) OR ($role_id == 2) ) {
return $this->redirect(array('controller' => 'dashboards'));
} else {
die('You are not authenticate person.');
//$this->Session->setFlash(__('You are not authenticate person.'), 'message', array('class' => 'danger'), 'auth');
}
} else {
die ('Something is wrong email id or password.');
//$this->Session->setFlash(__('You are not a register user still.'), 'message', array('class' => 'danger'), 'auth');
}
}
} else {
$this->Session->setFlash(__('invalidLoginDetails'), 'message', array('class' => 'danger'), 'auth');
}
}
login.ctp
<?php echo $this->Form->create('User',array('novalidate'=>'true','inputDefaults' => array('div' => false))); ?>
<?php echo $this->Form->input('email', array('type'=>'email', 'class'=>'form-control', 'placeholder'=>'Email', 'label'=>false)); ?>
<?php echo $this->Form->input('password', array('type'=>'password', 'class'=>'form-control', 'placeholder'=>'Password', 'label'=>false)); ?>
<?php echo $this->Form->end(__('Login'), array('class'=>'btn btn-default btn-block btn-clean'));?>