我現在已經通過該過程了系統,但出於某種原因,實際更新數據庫中密碼的代碼沒有更新任何內容?插入新密碼和重新密碼後,系統立即重定向到登錄頁面,即使沒有顯示錯誤?有什麼想法嗎?謝謝。重置密碼不會保存新密碼CakePHP 2.0
這是我的復位功能
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>
請幫助我,謝謝
上CTP文件的形式標記,你不令牌再次發送剛剛從表單標籤在你的CTP刪除操作,然後檢查 – 2014-10-09 05:11:41
@BharatMaheshwari是的,我使用驗證過 – dery 2014-10-09 05:12:44
我也看到了兩個表單標籤打開,一個一個被關閉,刪除第二個 – 2014-10-09 05:14:17