0

由于 vanilla CakePHP 在用户编辑视图中不能很好地处理密码字段(将散列密码回显到密码字段等),我正在尝试使用 dereuromark 的 PasswordableBehavior 来处理用户注册和密码更新。

我尝试按照教程(http://www.dereuromark.de/2011/08/25/working-with-passwords-in-cakephp/)进行以下更改,但服务器不断抛出错误。这里有什么问题?因为错误在 PasswordableBehavior.php 中,所以我不能 100% 确定我搞砸了。

用户控制器.php:

public function register() {
if ($this->request->is('post') || $this->request->is('put')) {
    $this->User->Behaviors->attach('Tools.Passwordable');
    if ($this->User->save($this->request->data, true, array('username', 'name', 'email', 'pwd', 'pwd_repeat', 'group_id'))) {
    $this->Session->setFlash(__('The user has been saved'), 'flash/success');
            $this->redirect(array('action' => 'index'));
} else {
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'), 'flash/error');
        }
    unset($this->request->data['User']['pwd']);
    unset($this->request->data['User']['pwd_repeat']);
}

register.ctp(可能的安全漏洞警报)

<?php 
echo $this->Form->create('User', array('role' => 'form'));
echo $this->Form->input('username', array('class' => 'form-control'));
echo $this->Form->input('name', array('class' => 'form-control'));
echo $this->Form->input('email', array('class' => 'form-control'));
echo $this->Form->input('password', array('class' => 'form-control'));
echo $this->Form->hidden('group_id', array('value'=>3));
echo $this->Form->submit('Submit', array('class' => 'btn btn-large btn-primary'));
echo $this->Form->end();

最后,服务器报错:

Strict (2048): Declaration of PasswordableBehavior::beforeValidate() should be compatible with ModelBehavior::beforeValidate(Model $model, $options = Array) [APP/Plugin/Tools/Model/Behavior/PasswordableBehavior.php, line 338]
Strict (2048): Declaration of PasswordableBehavior::beforeSave() should be compatible with ModelBehavior::beforeSave(Model $model, $options = Array) [APP/Plugin/Tools/Model/Behavior/PasswordableBehavior.php, line 338]
4

1 回答 1

1

1)严格的错误不是什么大问题。IMO 只是关闭严格错误报告。

2)您看到的错误是因为 Behavior (beforeValidate()beforeSave()) 中的两种方法没有完整的选项。

只要确保他们有正确的选项,如下所示,严格的错误就会消失:

public function beforeValidate(Model $model, $options = array()) {
    //...

public function beforeSave(Model $model, $options = array()) {
    //...
于 2013-12-19T05:30:16.020 回答