我正在尝试重置密码,但它没有更新。有人能解决这个问题吗我收到一条错误消息,说我没有提交足够的非代码,所以这是填充。
这是reset.ctp:
<?php echo $this->Form->create('User', array('action' => 'reset')); ?>
<?php
echo $this->Form->input('password',array("type"=>"password","name"=>"data[User][password]"));
echo $this->Form->input('password_confirm',array("type"=>"password","name"=>"data[User][password_confirm]"));
echo $this->Form->submit();
echo $this->Form->end();?>
这是UsersController.php中的重置方法
function reset($token=null){
//$this->layout="Login";
$this->User->recursive=-1;
if(!empty($token)){
$u=$this->User->findBytokenhash($token);
if($u){
$this->User->id=$u['User']['id'];
if(!empty($this->data)){
$this->User->data=$this->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;
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('/');
}
}
答案 0 :(得分:0)
我在reset.ctp中使用了这个,密码更新了:echo $ this-&gt; Form-&gt; input(&#39; password&#39;);