PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules_core/sessions/models/mdl_recover.php

https://bitbucket.org/hlevine/myclientbase-south-african-version
PHP | 56 lines | 32 code | 24 blank | 0 comment | 2 complexity | f8a4d2404498001d8bf0afe9c7dd4c49 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, GPL-2.0
  1. <?php (defined('BASEPATH')) OR exit('No direct script access allowed');
  2. class Mdl_Recover extends MY_Model {
  3. function validate_recover() {
  4. $this->load->library('form_validation');
  5. $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
  6. $this->form_validation->set_rules('username', $this->lang->line('username'), 'required');
  7. return parent::validate();
  8. }
  9. function recover_password($username) {
  10. $this->db->where('username', $username);
  11. $query = $this->db->get('mcb_users');
  12. if ($query->num_rows()) {
  13. $this->load->helper('mailer/phpmailer');
  14. $this->load->helper('text');
  15. $user = $query->row();
  16. if ($user->email_address) {
  17. $password = random_string();
  18. $this->db->where('user_id', $user->user_id);
  19. $this->db->set('password', md5($password));
  20. $this->db->update('mcb_users');
  21. $from = $user->email_address;
  22. $to = $user->email_address;
  23. $subject = $this->lang->line('password_recovery');
  24. $email_body = $this->lang->line('password_recovery_email') . ' ';
  25. $email_body .= $password . '<br />' . anchor(site_url(), $this->lang->line('password_recovery_email_2'));
  26. $this->mdl_mcb_data->set_session_data();
  27. phpmail_send($from, $to, $subject, $email_body);
  28. }
  29. }
  30. }
  31. }
  32. ?>