我在 CakePHP 2.x. 中创建了一个登录系统,用户可以从他的电子邮件地址和他的电话号码登录。我想要的是如果用户提供电话号码,例如“123456789”或“+123456789”,他可以登录系统。有时现在只有一项任务可以通过这个来完成。如果数据库中的号码是这个“123456789”,他就不能从这个“+123456789”登录。
我想我必须在模型类中应用规则......
$this->Auth->authenticate = array(
'Authenticate.Cookie' => array(
'fields' => array(
'username' => 'email',
'password' => 'password'
),
'userModel' => 'User',
'scope' => array('User.active' => 1)
),
'Authenticate.MultiColumn' => array(
'fields' => array(
'username' => 'email',
'password' => 'password'
),
'columns' => array('email', 'mobileNo'),
'userModel' => 'User',
)
);
}
这是从电子邮件和手机号码登录的代码:
登录功能
public function login() {
if ($this->Auth->login() || $this->Auth->loggedIn()) {
$this->redirect('/users/dashboard');
}else{
$this->layout='logindefault';
$this->set('title_for_layout', 'Account Login');
if ($this->request->is('post')) {
if ($this->Auth->login() || $this->Auth->loggedIn()) {
if ($this->Session->check('Auth.User')){
$this->_setCookie($this->Auth->user('idUser'));
$this->redirect('/users/dashboard');
}
}else {
$this->Session->setFlash('Incorrect Email/Password Combination');
}
}
}
}