diff --git a/application/controllers/User.php b/application/controllers/User.php index fa990099..c5649548 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -527,19 +527,9 @@ class User extends CI_Controller { // Send email with reset code - $config = Array( - 'protocol' => 'smtp', - 'smtp_host' => 'smtp.mailtrap.io', - 'smtp_port' => 2525, - 'smtp_user' => '2a4ee81ff3810f', - 'smtp_pass' => 'bd4ec48aa67b14', - 'crlf' => "\r\n", - 'newline' => "\r\n" - ); - $this->data['reset_code'] = $reset_code; $this->load->library('email'); - $this->email->initialize($config); + $message = $this->load->view('email/forgot_password', $this->data, TRUE); $this->email->from('noreply@cloudlog.co.uk', 'Cloudlog'); @@ -559,4 +549,36 @@ class User extends CI_Controller { } } } -} + + function reset_password($reset_code = NULL) + { + $data['reset_code'] = $reset_code; + if($reset_code != NULL) { + $this->load->helper(array('form', 'url')); + + $this->load->library('form_validation'); + + $this->form_validation->set_rules('password', 'Password', 'required'); + $this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required|matches[password]'); + + if ($this->form_validation->run() == FALSE) + { + $data['page_title'] = "Reset Password"; + $this->load->view('interface_assets/mini_header', $data); + $this->load->view('user/reset_password'); + $this->load->view('interface_assets/footer'); + } + else + { + // Lets reset the password! + $this->load->model('user_model'); + + $this->user_model->reset_password($this->input->post('password', true), $reset_code); + $this->session->set_flashdata('notice', 'Password Reset.'); + redirect('user/login'); + } + } else { + redirect('user/login'); + } + } +} \ No newline at end of file diff --git a/application/models/User_model.php b/application/models/User_model.php index 21272ba0..5f18f212 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -413,6 +413,25 @@ class User_Model extends CI_Model { $this->db->update('users', $data); } + /* + * FUNCTION: reset_password + * + * Sets new password for users account where the reset code matches then clears the password reset code and password reset date. + * + * @param string $password + * @return string $reset_code + */ + function reset_password($password, $reset_code) { + $data = array( + 'user_password' => $this->_hash($password), + 'reset_password_code' => NULL, + 'reset_password_date' => NULL + ); + + $this->db->where('reset_password_code', $reset_code); + $this->db->update('users', $data); + } + // FUNCTION: bool _auth($password, $hash) // Checks a password against the stored hash private function _auth($password, $hash) { diff --git a/application/views/email/forgot_password.php b/application/views/email/forgot_password.php index f7361aa9..36855ce0 100644 --- a/application/views/email/forgot_password.php +++ b/application/views/email/forgot_password.php @@ -5,6 +5,9 @@ You or someone else has requested a password reset on your Cloudlog account. Your password reset code is: +Click here to reset password + + If you didn't request this just ignore. Regards, diff --git a/application/views/user/reset_password.php b/application/views/user/reset_password.php new file mode 100644 index 00000000..f5e84bb4 --- /dev/null +++ b/application/views/user/reset_password.php @@ -0,0 +1,47 @@ +
+
+
+
+
+
+

+

Reset Password?

+

You can reset your password here.

+
+ + + + + +
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ + +
+ +
+
+
+
+
+
+
\ No newline at end of file