CakeDC Users login with username

为君一笑 提交于 2019-12-08 13:47:30

Try configuring it on the $components in AppController:

public $components = array(
    'Auth' => array(
        'authenticate' => array(
            'Form' => array(
                'fields' => array('username' => 'username')
            )
        )            
    )
}

I had the problem on the inverse way, I wanted to validate users with their mail, and not username, and using the above configuration with 'username' => 'email' worked for me.

EDIT:

public $components = array(
    'Acl',
    'Auth' => array(
        'authorize' => array(
            'Actions' => array('actionPath' => 'controllers')
        ),
        'authenticate' => array(
            'Form' => array(
                'fields' => array('username' => 'email')
            )
        )            
    ),
    'Session'
);

public function beforeFilter() {
    //User settings
    $this->activeUserId = $this->Auth->user;
    $this->set('activeuserphoto', $this->Auth->user('photo'));
    $this->set('activeusername', $this->Auth->user('username'));

    //Configure AuthComponent
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
    $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
    $this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'dashboard');
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!