I am working on cakephp 2.x.i have a table in my database name user and it has 4 fields id, email, password and mobileNo
i have two fie
Use this code in app controller in beforefilter();
AuthComponent::$sessionKey = 'Auth.User';
if ($this->request->is('post') && $this->action == 'login') {
$username = $this->request->data['User']['email'];
if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
$this->Auth->authenticate = array(
'Form' => array(
'fields' => array(
'username' => 'email', //Default is 'username' in the userModel
'password' => 'password'), //Default is 'password' in the userModel
// 'scope'=>array('User.status' => '1'),
'userModel' => 'User'
)
);
}else{
$this->Auth->authenticate['Form']['fields']['email'] = 'mobile';
$this->request->data['User']['mobile'] = $username;
unset($this->request->data['User']['email']);
$this->Auth->authenticate = array(
'Form' => array(
'fields' => array(
'username' => 'mobile', //Default is 'username' in the userModel
'password' => 'password'), //Default is 'password' in the userModel
// 'scope'=>array('User.status' => '1'),
'userModel' => 'User'
)
);
}
}
$this->request->data['User']['email'] is my form field in which I am sending email or mobile.