2012-04-20 3 views
6

の電子メールを使用して私が持っているCakePHPの2.0認証私の見解では代わりに、ユーザー名

function beforeFilter(){ 
     $this->Auth->allow('sign_up', 'login', 'logout', 'forgot_password'); 
     return parent::beforeFilter(); 
    } 
public function login() { 
     if ($this->Auth->login()) { 
      $this->Session->setFlash(__('Successfully logged in'), 'default', array('class' => 'success')); 
      $this->redirect($this->Auth->redirect()); 
     } else { 
      if (!empty($this->request->data)) { 
       $this->Session->setFlash(__('Username or password is incorrect'), 'default', array('class' => 'notice')); 
      } 
     } 
    } 

しかし、ログインがあります働いていない、何が欠けている?

ありがとうございました。

答えて

14

私は問題があると考えている:カスタムログインフィールドはCakePHPの1.3に指定された方法だった

function beforeFilter(){ 
    $this->Auth->fields = array(
     'username' => 'email', 
     'password' => 'password' 
    ); 
} 

。代わりにCakePHP 2.0では public $components = array(...);にこれらのフィールドを指定する必要があります。 1.3 APIは、Authに$ fieldsプロパティがあることを示していますが、 2.0 APIには$ fieldsプロパティが存在しないことが示されています。ですから、次の条件を満たす必要があります。

public $components = array(
    'Session', 
    'Auth' => array(
     'authenticate' => array(
      'Form' => array(
       'fields' => array('username' => 'email') 
      ) 
     ) 
    ) 
); 

詳しい情報はで見つけることができます:http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#configuring-authentication-handlers

それがうまくいく方法を教えてください!

0

私の問題の最終的な解決策。ありがとうございました。

私はuserModelに問題があったと私は、この書き込み:これに代えて

'Auth' => array(
     'userModel' => 'Member' 
    ) 

を:

'Auth' => array(
    'authenticate' => array(
     'Form' => array(
      'userModel' => 'Member' 
     ) 
    ) 
) 
関連する問題