-
-
Save good-orbit/95299cbeea92c393f7ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CONTROLLER | |
public function retrieve() | |
// REQUEST PASSWORD RESET | |
// LOADED WHEN THE FORM IS SUBMITTED OFF THE PASSWORD PAGE AND SENDS THE EMAIL WITH TOKEN AND INSTRUCTIONS | |
{ | |
$this->load->library('form_validation'); | |
$this->load->library('session'); | |
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); | |
$this->load->model('user_model', 'um'); | |
$this->load->library('encrypt'); | |
$this->load->helper('url'); | |
$submit = $this->input->post('submit'); | |
if($submit) | |
// IF THE SUBMIT BUTTON IS SET | |
{ | |
// START PROCESS TO CREATE $USER VARIABLE THAT HOLDS WHAT THE USER ENTERED IN THE FORM AND THAT CAN GET CHECKED AGAINST THE DB IN THE MODEL | |
$user = $this->um->validate_retrieve(array('email' => $this->input->post('email'))); | |
// IF THE USER IS CREATED AND CHECKS OUT AND ALL OF THE ERRORS ARE CLEARED ON THE FORM | |
if( $user && $this->form_validation->run() == TRUE ) { | |
$domain = "clci.dev/index.php"; | |
// CREATE A TOKEN LINK TO SEND TO THE USERS EMAIL THAT EXIST IN THE DB AND WAS ENTERED | |
$token = sha1($user->email.$user->salt).dechex($user->id); | |
$link = "http://www.".$domain."/auth/reset/?token=$token"; | |
{ | |
$this->load->library('email'); | |
$this->email->from('noreply@cysticlife.org', 'CysticLife'); | |
$this->email->to($user->email); | |
$this->email->subject('Reset Password'); | |
$this->email->message("Please go to the following web address to reset your password:\n\n$link\n\n-Your friends at CysticLife\n\nPlease remember to add the cysticlife.org domain to your address book to ensure that you receive your CysticLife e-Notifications as requested."); | |
$this->email->send(); | |
redirect('auth/success'); | |
exit; | |
} | |
$this->form_validation->run() == FALSE; | |
$data['main_content'] = 'auth/password'; | |
$this->load->view('includes/templates/main_page_template', $data); | |
} | |
$this->form_validation->run() == FALSE; | |
$data['email_error'] = 'This email is invalid'; | |
$data['main_content'] = 'auth/password'; | |
$this->load->view('includes/templates/main_page_template', $data); | |
} | |
} | |
//MODEL | |
//CHECK THE EMAIL THE USER ENTERED TO RESET THEIR PASSWORD AGAINST THE MATCHING ONE IN THE DB | |
public function validate_retrieve($data) { | |
$query = $this->db->where($data)->get('users', '1'); | |
foreach ($query->result() as $user) | |
{ | |
return $user->email; | |
} | |
$reset_token = array( | |
'token' => $token, | |
'email' => $user->email | |
); | |
$insert = $this->db->insert('reset', $reset_token); | |
return $reset_token; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment