0

我在尝试设置 AuthComponent 时完全迷失了。每次登录都会失败。

这是我的 AppControllerbeforeFilter功能:

public function beforeFilter() {

    $this->Auth->authenticate = array(
        'all' => array(
            'userModel' => 'ClientUser',
            'fields' => array(
                'username' => 'login',
                'password' => 'password'
            )
        )
    );

    $this->Auth->loginAction = array('controller' => 'client_users', 'action' => 'login');
    $this->Auth->loginRedirect = array('controller' => 'static', 'action' => 'clientcenter');
    $this->Auth->logoutRedirect = array('controller' => 'static', 'action' => 'home');

    // I deny stuff later on
    $this->Auth->allow();
}

login是 ClientUsers 控制器中的函数:

public function login() {

    // Check login data
    if ($this->Auth->login()) {
        return $this->redirect($this->Auth->redirect());
    } else {
        $this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
    }
}

而且总是失败。我不知道为什么。

这是我的$request->data内容:(我实际上使用“登录”和“用户名”作为字段名,没有用)

ClientUser
    login: user@email.com
    password: thepassword

客户端密码在模型中使用 authcomponent 进行哈希处理(在脚本顶部导入。我之前使用了安全哈希函数,但这也不起作用):

public function beforeSave($options) {

    $this->data['ClientUser']['password'] = AuthComponent::password($this->data['ClientUser']['password1']);

    return true;
}
4

1 回答 1

1

你在哪里 Auth 适配器?如http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#authentication-objects中所述

// at least one adapter is necessary (here Form)
public $components = array(
    'Auth' => array(
        'authenticate' => array(
            'Form' => array(
                'fields' => array('username' => 'email')
            )
        )
    )
);
于 2013-02-19T13:33:11.627 回答