Cakephp,未找到身份验证适配器表单

时间:2014-01-20 08:30:29

标签: php cakephp-2.0

即时开发小应用程序,我决定使用CakePhp作为框架,我是doint教程,以制作"帖子"。但是,当我想使用来自here的功能Simple Authentication and Authorization Application时,我正在进行复制和粘贴,并遇到了2个问题

首先我的User模型没有看到SimplePasswordHasher

App::uses('SimplePasswordHasher', 'Controller/Component/Auth');
class User extends AppModel {
    public $validate = array(
    'username' => array(
        'required' => array(
            'rule' => array('notEmpty'),
            'message' => 'A username is required'
        )
    ),
    'password' => array(
        'required' => array(
            'rule' => array('notEmpty'),
            'message' => 'A password is required'
        )
    ),
    'role' => array(
        'valid' => array(
            'rule' => array('inList', array('admin', 'author')),
            'message' => 'Please enter a valid role',
            'allowEmpty' => false
        )
    )
);

public function beforeSave($options = array()) {
    if (isset($this->data[$this->alias]['password'])) {
        $passwordHasher = new SimplePasswordHasher(); <---- here
        $this->data[$this->alias]['password'] = $passwordHasher->hash(
                $this->data[$this->alias]['password']
        );
    }
    return true;
}}

也许App::uses('SimplePasswordHasher', 'Controller/Component/Auth');并未指向正确的位置,但我找不到检查它的方法。

第二个问题是,当我尝试进入登录页面时,我得到Authentication adapter "Form" was not found。我可以在哪里启动该适配器。任何帮助都会很棒。

1 个答案:

答案 0 :(得分:0)

您必须在控制器中指定相同的SimplePasswordHasher,如下所示:

public $components = array(
    'Auth' => array(
        'loginAction' => array(
            'controller' => 'users',
            'action' => 'login'
        ),
        'authError' => 'Did you really think you are allowed to see that?',
        'authenticate' => array(
            'Form' => array(
                'passwordHasher' => array(
                    'className' => 'Simple',
                    'hashType' => 'sha256'
                )
            )
        ),
        'loginRedirect' => array(
            'controller' => 'users',
            'action' => 'index'
        )
    )
);

希望有所帮助