我正在为我的站点开发一些管理功能,具有管理员权限的用户能够为给定的用户 ID 打开表单。通过这种形式,他们可以更改用户权限、更改用户密码或其他方式。
但是,当从模型构造表单时,密码字段会从数据库中提取散列密码并填充密码字段。结果,当管理员保存表单时,散列密码被视为明文,因此再次散列,覆盖原始密码。
我需要的是某种方法来允许管理员用户更改表单,但只有在更改时才在数据库上散列和更新密码。
我的想法是将表单设置密码构造为空白:
查看/用户/edit.ctp:
echo $this->Form->input('User.password',array(
'value' => '',
'type' => 'password',
'autocomplete' => 'off'
)
);
save
并对跳过密码进行某种检查;但这就是我卡住的地方。
控制器/用户控制器.php
public function edit($id = null)
{
$this->User->id = $id;
if ($this->request->is('get'))
{
$this->request->data = $this->User->read();
} else {
//Something here????
if ($this->User->save($this->data))
{
$this->Session->setFlash('Your user has been updated.');
$this->redirect(array('action' => 'index'));
} else
{
$this->Session->setFlash('Unable to update your user.');
}
}
$this->set('groups',$this->User->Group->find('list'));//, array( 'fields' => array('id', 'name'))));
$this->set('sites',$this->User->Site->find('list'));//, array( 'fields' => array('id', 'name'))));
}
如果没有更改,如何检查并防止密码更新?
决定的解决方案:
根据提供的答案,我在同一页面上使用了第二个表单,该表单重新使用了用户通过的注册验证。更新站点/组权限时,用户通过一种形式发送,而密码通过另一种形式发送。