Codeigniter - Passwort Vergessen

Hallo: ich brauche zur Umsetzung einer "Passwort vergessen" auf der Anmeldeseite. Hier erklärte ich was ich habe, so weit.

  1. Erholen Ansicht ist Aufforderung zum empfangen von E-Mail-Eingang
  2. Funktion email_exists() überprüfen E-Mail. Wenn dem so ist, send_email() mit $temp_pass key und link.Die Datenbank speichern $temp_pass für weitere Maßnahmen und überprüfung.
  3. Benutzer klickt auf den link vorher geschickt vorbei $temp_pass Funktion reset_password.
  4. Die Modell-controller überprüfen $temp_pass mit der Datenbank. Wenn dem so ist, laden anzeigen zur Eingabe neues Passwort - und hier ist, wo ich bin stecken, weil die form verweist auf einen controller, der nicht erkennt $temp_pass also keine Passwort zurücksetzen.

Wie kann ich abgerufen das neue Kennwort ein, verbunden mit dem richtigen Benutzer und Passwort zurücksetzen?

Folgenden Code:

Controller

    public function recover(){
    //Loads the view for the recover password process.
    $this->load->view('recover');
}
public function recover_password(){
    $this->load->library('form_validation');
    $this->form_validation->set_rules('email', 'Email', 'required|trim|xss_clean|callback_validate_credentials');

            //check if email is in the database
        $this->load->model('model_users');
        if($this->model_users->email_exists()){
            //$them_pass is the varible to be sent to the user's email 
            $temp_pass = md5(uniqid());
            //send email with #temp_pass as a link
            $this->load->library('email', array('mailtype'=>'html'));
            $this->email->from('[email protected]', "Site");
            $this->email->to($this->input->post('email'));
            $this->email->subject("Reset your Password");

            $message = "<p>This email has been sent as a request to reset our password</p>";
            $message .= "<p><a href='".base_url()."main/reset_password/$temp_pass'>Click here </a>if you want to reset your password,
                        if not, then ignore</p>";
            $this->email->message($message);

            if($this->email->send()){
                $this->load->model('model_users');
                if($this->model_users->temp_reset_password($temp_pass)){
                    echo "check your email for instructions, thank you";
                }
            }
            else{
                echo "email was not sent, please contact your administrator";
            }

        }else{
            echo "your email is not in our database";
        }
}
public function reset_password($temp_pass){
    $this->load->model('model_users');
    if($this->model_users->is_temp_pass_valid($temp_pass)){

        $this->load->view('reset_password');

    }else{
        echo "the key is not valid";    
    }

}
public function update_password(){
    $this->load->library('form_validation');
        $this->form_validation->set_rules('password', 'Password', 'required|trim');
        $this->form_validation->set_rules('cpassword', 'Confirm Password', 'required|trim|matches[password]');
            if($this->form_validation->run()){
            echo "passwords match"; 
            }else{
            echo "passwords do not match";  
            }
}

Model_users

    public function email_exists(){
    $email = $this->input->post('email');
    $query = $this->db->query("SELECT email, password FROM users WHERE email='$email'");    
    if($row = $query->row()){
        return TRUE;
    }else{
        return FALSE;
    }
 }
public function temp_reset_password($temp_pass){
    $data =array(
                'email' =>$this->input->post('email'),
                'reset_pass'=>$temp_pass);
                $email = $data['email'];

    if($data){
        $this->db->where('email', $email);
        $this->db->update('users', $data);  
        return TRUE;
    }else{
        return FALSE;
    }

}
public function is_temp_pass_valid($temp_pass){
    $this->db->where('reset_pass', $temp_pass);
    $query = $this->db->get('users');
    if($query->num_rows() == 1){
        return TRUE;
    }
    else return FALSE;
}
Sehen Sie, wie Ionen-auth macht.

InformationsquelleAutor crg821 | 2013-01-06

Schreibe einen Kommentar