我现在已经让系统完成了这个过程,但是由于某种原因,实际更新数据库中密码的代码没有更新任何东西?输入新密码并重新输入密码后,系统立即重定向到登录页面,即使没有显示错误?有什么想法吗?谢谢。
这是我的重置功能
function reset($token=null){
$this->User->recursive=-1;
if(!empty($token)){
$u=$this->User->findBytokenhash($token);
if($u){
$this->User->id=$u['User']['id'];
if($this->request->is('post')){
$this->User->data=$this->request->data;
$this->User->data['User']['username']=$u['User']['username'];
$new_hash=sha1($u['User']['username'].rand(0,100));//created token
$this->User->data['User']['tokenhash']=$new_hash;
// print_r($this->request->data);
// exit;
if($this->User->validates(array('fieldList'=>array('password','password_confirm')))){
if($this->User->save($this->User->data)){
$this->Session->setFlash('Password Has been Updated');
$this->redirect(array('controller'=>'users','action'=>'login'));
}
} else{
$this->set('errors',$this->User->invalidFields());
}
}
} else {
$this->Session->setFlash('Token Corrupted,,Please Retry.the reset link work only for once.');
}
} else{
$this->redirect('/');
}
}
这是我的reset.ctp
<?php echo $this->Form->create('User', array('action' => 'reset')); ?>
<?php
if(isset($errors)){
echo '<div class="error">';
echo "<ul>";
foreach($errors as $error){
echo "<li><div class='error-message'>$error</div></li>";
}
echo "</ul>";
echo '</div>';
}
?>
<form method="post">
<?php
echo $this->Form->input('User.password', array('type' => 'password',
'name' => '$data[User][password]',
'class' => 'form-control'));
echo $this->Form->input('User.re_password', array('type' => 'password',
'name' => 'data[User][re_password]',
'class' => 'form-control'));
?>
<input type="submit" class="button" style="float:left;margin-left:3px;" value="Save" />
<?php echo $this->Form->end();?>
</form>
请帮帮我,谢谢