【发布时间】:2014-05-13 15:19:02
【问题描述】:
目前正在为我负责的 CakePHP 应用程序编写密码重置脚本。
到目前为止,我有一个忘记的脚本,我创建了一个随机字符串,将其添加到相关用户并通过电子邮件向用户发送重置链接。 (域名实际上是活的)
Click on the link below to Reset Your Password
Click here to Reset Your Password
or Visit this Link
domainnamehere/users/reset/e9bb0ab37ff9175a856f0aff3e18db801451306e5a50bfc618c43280b62628e4bdb8131b638e042b47d42ca1516de11f1b025d646406bfd31054db167d5ef430#62442a331b1f9a3e37cbb9a33c1d619b8a8e0a18
This email was sent using the CakePHP Framework
单击重置并加载重置表单后,它似乎直接跳到我最后一个没有令牌值的 else 语句?
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_retype')))){
if($this->User->save($this->User->data))
{
$this->Session->setFlash('Password Has been Updated');
$this->redirect(array('controller'=>'users','action'=>'login'));
}
else
{
$this->Session->setFlash('Error updating values');
}
}
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('/');
$this->Session->setFlash($token);
}
}
重置.ctp
<div class="users form">
<?php echo $this->Form->create('User', array('action' => 'reset')); ?>
<fieldset>
<legend><?php echo __('Change your Password'); ?></legend>
<?php
//debug($users);
echo $this->Form->input('password', array('label' => 'Change password'));
echo $this->Form->input('password_retype', array('label' => 'Confirm password', 'type' => 'password'));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
在我遇到困难时,我们将不胜感激任何对这种情况的帮助,谢谢!
【问题讨论】:
-
我很困惑,你是在调用你的 forgot() 还是你的 reset()?
-
看看函数是如何被调用的也很有用,因为你没有得到
$token参数。 -
我正在调用我的重置,忘记功能工作正常。您想查看 .ctp 文件吗?
-
请。同时删除问题的忘记功能,这里显然没有必要。如果 .ctp 文件太大,只需发布表单(并提交)部分即可。
-
为您编辑了问题,谢谢。基本上,它总是到最后一个 else,我不知道为什么