パスワード変更機能に検証を追加しようとしていますが、機能しません。
私が追加しました
->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');
// }
// }
}
検証せずにデータを保存します。解決策は何ですか?