我正在cakephp 2.x上工作..我想要的是我想從電子郵件和電話號碼登錄用戶...如果用戶在登錄時鍵入數字添加'+'他可以登錄到系統..所以我想先檢查,如果輸入的數字有「+」或沒有..如果不連接+與數字,然後處理查詢..我不dont知道我可以在身份驗證組件中使用這個作爲我AUTH autometically登錄用戶..當用戶登錄時字符串連接Cakephp
例如1234556: 添加+則:1234556
我 登錄.ctp我的輸入框的名字是'電子郵件'其中號碼或電子郵件正在添加是
這裏是我的控制器
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() {
$mobileNo=$this->request->data['User']['email'];
$pos = strpos($mobileNo,'@');
if($pos){
echo 'yes';
}else {
$mystr=substr($mobileNo,0,1);
if ($mystr!='+'){
$mobileNo = '+'.$mobileNo;
}
}
// DONT KNow how can i pass this mobile No
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');//this will redisplay the login page
}
}}
}
現在種類的副本你的http://stackoverflow.com/questions/17338364/cakephp-phone-number-validation – mark