2013-06-27 21 views
0

我正在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 
     } 
    }} 
} 
+0

現在種類的副本你的http://stackoverflow.com/questions/17338364/cakephp-phone-number-validation – mark

回答

1

你應該更新$這個 - >請求,因此

$this->request->data['User']['email'] = $mobileNo; // there $mobileNo is your updated value 

,你應該到它之前$this->Auth->login()

+0

nope ..它沒有工作 – hellosheikh

+0

以及我在數據庫中提到這裏有兩個單獨的字段mobileNo和電子郵件...但login.ctp文件名中只有一個輸入字段email ...所以如果用戶輸入電子郵件我的查詢檢查電子郵件或如果他鍵入數字查詢檢查mobileNo字段... – hellosheikh

+0

謝謝它的工作原理 – hellosheikh

相關問題