0

我正在开发一个 cakephp 2.x .. 我想要的是我想从电子邮件和电话号码登录用户......如果用户在登录期间他输入了没有添加“+”的号码,他可以能够登录系统..所以我想先检查输入的数字是否有“+”..如果没有将+与数字连接,然后处理查询..我不知道如何在身份验证组件中使用它作为我授权自动记录用户..

示例 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
        }
    }}
}
4

1 回答 1

1

你应该更新 $this->request,所以

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

你应该在之前$this->Auth->login()

于 2013-06-27T12:24:34.820 回答