Php 检索忘记的密码

Php 检索忘记的密码,php,codeigniter,Php,Codeigniter,在下面的代码中,我使用了codeigniter代码,我在db中输入了用户名和密码。但是我想检索我忘记的密码。我尝试了,但是我得到了以下错误,请帮助确认问题 控制器: <?php class Login extends CI_Controller { function index() { $data['main_content'] = 'login_form'; $this->load->view('includes/templ

在下面的代码中,我使用了codeigniter代码,我在db中输入了用户名和密码。但是我想检索我忘记的密码。我尝试了,但是我得到了以下错误,请帮助确认问题

控制器:

<?php

class Login extends CI_Controller {

    function index()
    {
        $data['main_content'] = 'login_form';
        $this->load->view('includes/template', $data);      
    }

    function validate_credentials()
    {       
        $this->load->model('membership_model');
        $query = $this->membership_model->validate();

        if($query) // if the user's credentials validated...
        {
            $data = array(
                'username' => $this->input->post('username'),
                'is_logged_in' => true
            );
            $this->session->set_userdata($data);
            redirect('site1/members_area');
        }
        else // incorrect username or password
        {
            $this->index();
        }
    }   

    function signup()
    {
        $data['main_content'] = 'signup_form';
        $this->load->view('includes/template', $data);
    }

    function create_member()
    {
        $this->load->library('form_validation');

        // field name, error message, validation rules
        $this->form_validation->set_rules('first_name', 'Name', 'trim|required');
        $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
        $this->form_validation->set_rules('email_address', 'Email Address', 'trim|required|valid_email');
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
        $this->form_validation->set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]');
         $this->load->helper('date');

        if($this->form_validation->run() == FALSE)
        {
            $this->load->view('signup_form');
        }

        else
        {           
            $this->load->model('membership_model');

            if($query = $this->membership_model->create_member())
            {
                $data['main_content'] = 'signup_successful';
                $this->load->view('includes/template', $data);
            }
            else
            {
                $this->load->view('signup_form');           
            }
        }

    }
    public function forgot_password()
{
    $this->form_validation->set_rules('email_address','Email Address','trim|required|valid_email|callback__check_email_exists');

    if($this->form_validation->run() == FALSE)
    {
       // VALIDATION ERRORS, SHOW VIEWS
       $this->index();
    }
    else
    {
      // ALL IS GOOD, UPDATE EMAIL, AND REDIRECT TO CURRENT URL
      $this->load->view('login_form');
    }
}
public function _check_email_exists($email)
{
  // LOAD AND USE YOUR MODEL TO CHECK EMAIL EXISTS HERE
  if ( ! $email_exists )
  {
    $this->form_validation->set_message('email_address', 'That email address don\'t exist, sucka!');
    return FALSE;
  }
  else
  {
    return TRUE;
  }
}
    function logout()
    {
        $this->session->sess_destroy();
        $this->index();
    }

}

首先,您需要控制器中的一个函数将用户带到遗忘的用户页面

public function forgot_pass(){
 $this->load->view('forgot_pass_view');
}
然后,您可能至少需要询问视图中的电子邮件地址。 创建另一个函数来验证控制器中的电子邮件地址,如果它匹配,则使用新的临时密码发送邮件

public function check_email(){
  $this->load->helper(array('form', 'url'));
  $this->load->library('form_validation');
  $this->form_validation->set_rules('email', 'email_check', 'callback_email_check');
  if ($this->form_validation->run() == FALSE){
   //throw error
  } else {
   //send email
  }
}
public function email_check(){
  //use this function to check if the email exists and return false if it is not the DB
}
public function forgot_pass(){
 $this->load->view('forgot_pass_view');
}
public function check_email(){
  $this->load->helper(array('form', 'url'));
  $this->load->library('form_validation');
  $this->form_validation->set_rules('email', 'email_check', 'callback_email_check');
  if ($this->form_validation->run() == FALSE){
   //throw error
  } else {
   //send email
  }
}
public function email_check(){
  //use this function to check if the email exists and return false if it is not the DB
}