Cakephp 2.0 Authentication using email instead of username

后端 未结 2 1368
北荒
北荒 2021-01-12 19:44

In my view I have:

Form->create(\'User\', array(\"controller\" => \"Users\", \"action\" => \"login\", \"method\" => \"pos         


        
相关标签:
2条回答
  • 2021-01-12 20:02

    Final solution for my problem. Thank you.

    I had a problem with userModel and I write this:

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

    instead of this:

    'Auth' => array(
        'authenticate' => array(
            'Form' => array(
                'userModel' => 'Member'
            )
        )
    )
    
    0 讨论(0)
  • 2021-01-12 20:03

    I believe the problem is:

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

    That was how custom login fields were specified in CakePHP 1.3. CakePHP 2.0 instead requires you to specify these fields in the public $components = array(...);. The 1.3 API shows that Auth has a $fields property, but the 2.0 API shows that there is no longer a $fields property. So you must:

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

    More information can be found at: http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#configuring-authentication-handlers

    Please tell me how it works out!

    0 讨论(0)
提交回复
热议问题