我是 cakephp 2.x 的新手,所以我不知道该怎么做.. 我想从他的电子邮件地址和电话号码登录用户..如果数据库中的号码是这个“12345”和用户,我的意图是什么正在尝试通过此号码“+12345”登录他可以登录系统..我已经编写了一个代码,但我不知道如何使用它或在 auth 组件中调整我的代码,因为 auth 组件正在自动记录用户 ..
这是我的控制器
public function beforeFilter() {
parent::beforeFilter();
$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');
/*$this->Auth->logout();
$cookie = $this->Cookie->read('Auth.User'); */
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');
}
}}
}
这是我要添加的代码..
$mobileNo='+123456789';
if (strpos($mobileNo,'+') !== false) {
$mobileNo=str_replace("+", "",$mobileNo);
}
?>