【发布时间】:2013-06-27 08:31:22
【问题描述】:
我是 cakephp 2.x 的新手,所以我不知道该怎么做。我想从用户的电子邮件地址和电话号码登录用户。如果数据库中的号码是“12345”,我的意图是什么并且用户正在尝试通过此号码“+12345”登录他可以登录系统..我已经编写了一个代码,但我不知道如何使用它或将身份验证组件中的代码调整为身份验证组件正在自动记录用户..
这是我的控制器
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);
}
?>
【问题讨论】:
标签: cakephp cakephp-2.0 cakephp-2.1