【发布时间】:2013-06-27 05:50:26
【问题描述】:
我在 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');
}
}
}
}
【问题讨论】:
-
可以在检查电话号码条件的同时完成,比如检查+字符串并删除它,&检查剩余号码..!!
-
@SiddeshBhalke 怎么样?
-
@HelloSheik 在此处粘贴您的登录操作代码,让我看看您做得如何..!
-
@SiddeshBhalke 我更新了我的问题
标签: regex cakephp cakephp-2.0 cakephp-2.1