我正在使用 cakePHP 2.0,并且正忙于为我的站点准备一个用户管理表单。问题是,当我从数据库中调用用户信息行时,它会以加密形式读取密码,然后用长字符串填充表单元素(我假设是加密密码)。
保存时,我的验证规则中断,因为我限制为 8 个字符(这是一件好事,因为我不想保存密码的加密版本)。
我也不能将该字段留空,因为它可能会导致人们再次保存并未能通过验证规则(未输入密码)
克服这个问题的最佳方法是什么?我想过用 8 个字符的虚拟密码替换该行的填充密码并进行验证检查,但是,这不起作用,因为 a) 有人可以使用相同的密码,并且 b) 我需要再次查找以获取原始密码再次这没有意义。
有什么帮助吗?
// Controller EDIT:
public function edit($id = null) {
$this->User->id = $id;
if(!$this->User->exists()) {
$this->Session->setFlash(__('The user does not exist'));
$this->redirect(array('action' => 'index'));
} else {
if($this->request->is('post') || $this->request->is('put')) {
if($this->User->save($this->request->data)) {
$this->Session->setFlash('The user has been updated','default',array('class'=>'success'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
$this->request->data = $this->User->read(null, $id);
$userTypes = $this->User->UserType->find("list");
$userStatuses = $this->User->UserStatus->find("list");
$this->set(compact("userTypes","userStatuses"));
}
}
// HTML Form:
<?php echo $this->Form->create('User');?>
<fieldset>
<legend><?php echo __('Modify User '); ?></legend>
<h3><?php echo $this->Html->link("Return to user index",array("controller" => "users","action" => "index")); ?></h3>
<?php
echo $this->Form->input('username');
echo $this->Form->input('password',array("id" => "profilePassword","empty" => true, "autocomplete" => "off"));
echo $this->Form->input('company');
echo $this->Form->input('first_name');
echo $this->Form->input('last_name');
echo $this->Form->input('telephone');
echo $this->Form->input('fax');
echo $this->Form->input('user_status_id');
echo $this->Form->input('user_type_id');
?>
</fieldset>
<?php echo $this->Form->end(__('Update'));?>