0

私はcakephp 2.xiに取り組んでおり、データベース名userにテーブルがあり、id、email、password、mobileNoの4つのフィールドがあります

login.ctpに 2 つのフィールドがあります

 <?php


 echo $this->form->create();

echo $this->form->input('email');
echo $this->form->input('password');


echo $this->form->end('submit');
 ?>

私が欲しいのは、Facebookが行ったのと同じように、彼のmobileNoからもユーザーにログインしたいです(彼が電子メールアドレスではなく携帯電話番号を入力した場合)..彼はhi電子メールアドレスまたはmobilenoでログインできます.別の入力を作成したくない.フィールド..これを行う方法がわからない ここに私のコードがあります

AppController

 class AppController extends Controller {
 public $components = array(
'Session',
'Auth'=>array(
'loginRedirect'=>array('controller'=>'users', 'action'=>'admin'),
'logoutRedirect'=>array('controller'=>'users', 'action'=>'admin'),
'authError'=>"You can't access that page",
'authorize'=>array('Controller'),
  'authenticate' => array(
   'Form' => array(
    'fields' => array('username' => 'email')
    )))
    );
 )
 );


public function isAuthorized($user) {
 }

 public function beforeFilter() {
 $this->Auth->allow('index');
 }
}

ユーザーコントローラー

 public function login()
  {
 if ($this->request->is('post')) {
   if ($this->Auth->login()) {
    $this->redirect($this->Auth->redirect());
} else {
    $this->Session->setFlash('Your email/password combination was incorrect');
   }
  }
  }
4

2 に答える 2

0

ここで解決策を見つけましたhttps://github.com/ceeram/Authenticate プラグインを使用してこの機能を実装しましたが、正常に動作します..

于 2013-06-16T07:43:53.860 に答える