我的codeigniter网站中的链接仅适用于重新加载

时间:2015-02-16 10:37:56

标签: javascript php codeigniter frameworks

我正在开发一个关于Codeigniter Framework的网站,我在设置忘记密码功能时遇到了问题。

当我提交我的电子邮件地址时,它会向该地址发送一封电子邮件,该电子邮件中包含一个带有令牌的链接。例如: http://www.myegsite.com/user/forgotyourpassword/2991c14654e1ed41aab1565dcf815b0f

点击该链接后,如果该令牌未过期,则网站会询问您的新密码并确认密码。

问题是:当我提供新密码并确认密码并单击“提交”按钮时,它会出现以下错误:

  

遇到错误
  不允许您请求的操作。

重新加载相同的链接后,我得到的页面工作得非常好,它会再次更新我的密码。

第一次链接不起作用的原因是什么?

控制器:

public function forgotyourpassword($token)
{
    if($this->session->userdata('user_data') != NULL)
    {
         redirect(base_url() . 'User');
    }else
    {
     //check if token exist in table or not , if not exist return false;
        $this->load->model("data_access/extradataaccess","ExtraDataAccess");
        $dbToken =$this->ExtraDataAccess->getToken($token);
        if($dbToken == FALSE)
            {
            $this->session->set_flashdata("invalid_token",'This token is invalid!');
            redirect(base_url() . 'welcome/forgotPassword');
        }
        else
        {
         //check if current date is smaller than expiry data , it means token is still valid return true;   
        if($this->ExtraDataAccess->GetTokenInfo($token) == FALSE)
        {
            //set flash data session for token expired

            redirect(base_url() . 'welcome/forgotPassword');

            //if token is expired return false
        } //if ($currDate <= $expiryDate)
        else
        {       
            // load form libraries
            $this->load->helper(array('form', 'url'));
            $this->load->library('form_validation');

            $this->form_validation->set_rules('password', 'Password', 'required|min_length[6]|max_length[20]');
            $this->form_validation->set_rules('confpassword', 'Password Confirmation', 'required|min_length[6]|max_length[20]|matches[password]');

            if($this->form_validation->run() == FALSE)
            { 
                $this->data['page_name'] = "Renew Password";
                $this->data['form_url'] = base_url()."user/forgotyourpassword/";
                $this->data['token'] = "$token";
                $this->load->view("welcome/renewpassword_view",$this->data);

            }
            else
            {   
                $tokenEmail = $this->ExtraDataAccess->GetTokenInfo($token)['email'];
                $hashPassword = md5($this->input->post('password'));

                //updating password into the database
                $updateData = array (

                    'password' => $hashPassword
                ); 
                $this->db->where('email',$tokenEmail);
                $this->db->update('users',$updateData);

            }  
           }//else
        }
    }//if($this->session->userdata('user_data') != NULL)
}//Forgotyourpassword()

查看:

<?php echo form_open("$form_url"."$token"); ?>
<div class="form-group">
    <label for="inputpass">Password</label>
    <input type="password" name="password" class="form-control" id="inputpass" value="" php echo placeholder="new password"/>
</div>
<?php if(form_error('password')!=NULL){
    echo "<div id='fielderror'>";
    echo form_error('password'); 
    echo "</div>";
}?>

<div class="form-group">
    <label for="inputpassconf">Confirm Password</label>
    <input type="password" name="confpassword" class="form-control" id="inputpassconf" value="" placeholder="confirm password"/>
</div>
<?php if(form_error('confpassword')!=NULL){
    echo "<div id='fielderror'>";
    echo form_error('confpassword'); 
    echo "</div>";
}?>

<h5><input type="submit" value="Reset Password" class="btn btn-info active"/></h5>

<?php echo form_close();?>

0 个答案:

没有答案