【发布时间】:2015-12-12 22:32:03
【问题描述】:
我正在尝试添加更改密码功能的验证,但它不起作用。
我已经添加了
->add('repeat_password', [
'equalToPassword' => [
'rule' => function ($value, $context) {
return $value === $context['data']['new_password'];
},
'message' => __("Your password confirm must match with your password.")
]
]);
到Users 模型
在我的控制器中
$user = $this->Users->get($this->_User['user_id']);
if ($this->request->is(['patch', 'post', 'put'])) {
$user = $this->Users->createEntity($user, ['password' => $this->request->data['repeat_password']]);
// $verify = (new DefaultPasswordHasher)->check($this->request->data['old_password'], $user->password);
// debug($verify);
//if ($verify) {
if ($this->Users->save($user)) {
$this->Flash->success('The password has been changed');
$this->redirect(['action' => 'index']);
} else {
$this->Flash->error('Password could not be issued');
}
}
// else {
// $this->Flash->error('Password Do not match');
// }
// }
}
它无需验证即可保存数据。解决办法是什么?
【问题讨论】:
-
请贴出方法
createEntity()的代码。 -
你能打印出你的
$user的值吗
标签: cakephp cakephp-3.0 cakephp-3.x