Can anyone clarify me how to add email instead of username while login
**'fields' => ['username' => 'username', 'password' => 'password']** ///////This is My code
**'fields' => ['username' => 'email', 'password' => 'password']** // I Tried Like that but it wont work for me
public function index()
{
$this->layout='mylayout';
$users = TableRegistry::get('tabl_reg');
$query = $users->find();
$this->set('results',$query);
if($this->request->is('post'))
{
$user = $this->Auth->identify();
if($user)
{
$this->Auth->setUser($user);
$session = $this->request->session();
$session->write('user_id',$user);
return $this->redirect(array('action' => 'home'));
}
else
?><script>alert("Your username or password is incorrect");</script><?php
}
}
But it will show always Alert message (if typing right email & password )
in same case while changing ‘fields’ => [‘username’ => ‘username’, ‘password’ => ‘password’] it is working …
$this->loadComponent('Auth', [
'loginAction' => ['controller' => 'Users', 'action' => 'index'],
'loginRedirect' => ['controller' => 'Users', 'action' => 'home'],
'logoutRedirect' => ['controller' => 'Users', 'action' => 'index'],
'unauthorizedRedirect' => $this->referer(),
'authError' => 'Error msg.',
'authenticate' => [
'Form' => [
'userModel' => 'Users', //i belive tabl_reg is the table for model Users correct? so it should be Users here
//'finder' => 'auth', //here you can create a custom finder if you need return more user information in the auth user session
'fields' => ['username' => 'email', 'password' => 'password'],
]
]
]);