0

CakePHP 2.x. でログイン システムを作成しました。このシステムでは、ユーザーはメール アドレスと電話番号からログインできます。私が望むのは、ユーザーが「123456789」や「+123456789」などの電話番号を提供すると、システムにログインできることです。時々、これによって達成できるタスクは 1 つだけです。データベース内の番号がこの「123456789」の場合、この「+123456789」からはログインできません。

モデルクラスにルールを適用する必要があると思います...

$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');
    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');
      }
    }
  }
}
4

1 に答える 1