Cakephp 2.0 Authentication using email instead of username

后端 未结 2 1367
北荒
北荒 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: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!

提交回复
热议问题