我在CakePHP 2.x.中创建了一个登录系统,用户可以从他的电子邮件地址和他的电话号码登录。我想要的是,如果用户提供电话号码,例如“123456789”或“+123456789”,他可以登录到系统。有时候现在只有一个任务可以通过这个来实现。如果数据库中的数字是“123456789”,他不能从这个“+123456789”登录。验证CakePHP中的用户电话号码
我想我已经在模型类应用规则...
$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');
}
}
}
}
它可以检查电话号码的条件,如检查+字符串,并将其删除,并检查剩余的数字。 –
@SiddeshBhalke怎么样? – hellosheikh
@ HelloSheik在这里粘贴你的登录行动代码,让我看看你在做什么..! –