Guest User

model

a guest
Jul 15th, 2017
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. <?php
  2. class user_model extends CI_model{
  3.  
  4.  
  5.  
  6. public function register_user($user){
  7.  
  8.  
  9. $this->db->insert('user', $user);
  10.  
  11. }
  12. public function login_user($email,$pass,$status,$level){
  13.  
  14. $this->db->select('*');
  15. $this->db->from('user');
  16. $this->db->where('email',$email);
  17. $this->db->where('password',$pass);
  18. $this->db->where('status',$status);
  19. $this->db->where('level',$level);
  20.  
  21.  
  22. if($query=$this->db->get())
  23. {
  24. return $query->row_array();
  25. }
  26. else{
  27. return false;
  28. }
  29.  
  30.  
  31. }
  32.  
  33.  
  34. public function email_check($email){
  35.  
  36. $this->db->select('*');
  37. $this->db->from('user');
  38. $this->db->where('email',$email);
  39. $query=$this->db->get();
  40.  
  41. if($query->num_rows()>0){
  42. return false;
  43. }else{
  44. return true;
  45. }
  46.  
  47. }
  48.  
  49.  
  50.  
  51.  
  52. //funtion to get email of user to send password
  53. public function ForgotPassword($email)
  54. {
  55. $this->db->select('email');
  56. $this->db->from('user');
  57. $this->db->where('email', $email);
  58. $query=$this->db->get();
  59. return $query->row_array();
  60. }
  61. public function sendpassword($data)
  62. {
  63. $email = $data['email'];
  64. $query1=$this->db->query("SELECT * from user where email = '".$email."' ");
  65. $row=$query1->result_array();
  66. if ($query1->num_rows()>0)
  67.  
  68. {
  69. $passwordplain = "";
  70. $passwordplain = rand(999999999,9999999999);
  71. $newpass['password'] = md5($passwordplain);
  72. $this->db->where('email', $email);
  73. $this->db->update('user', $newpass);
  74. $mail_message='Dear '.$row[0]['fname'].','. "\r\n";
  75. $mail_message.='Thanks for contacting regarding to forgot password,<br> Your <b>Password</b> is <b>'.$passwordplain.'</b>'."\r\n";
  76. $mail_message.='<br>Please Update your password.';
  77. $mail_message.='<br>Thanks & Regards';
  78. $mail_message.='<br>Your company name';
  79. date_default_timezone_set('Etc/UTC');
  80. require FCPATH.'assets/PHPMailer/PHPMailerAutoload.php';
  81. $mail = new PHPMailer;
  82. $mail->isSMTP();
  83. $mail->SMTPSecure = "tls";
  84. $mail->Debugoutput = 'html';
  85. $mail->Host = "yooursmtp";
  86. $mail->Port = 587;
  87. $mail->SMTPAuth = true;
  88. $mail->Username = "your@email.com";
  89. $mail->Password = "password";
  90. $mail->setFrom('admin@site', 'admin');
  91. $mail->IsHTML(true);
  92. $mail->addAddress($email);
  93. $mail->Subject = 'OTP from company';
  94. $mail->Body = $mail_message;
  95. $mail->AltBody = $mail_message;
  96. if (!$mail->send()) {
  97. $this->session->set_flashdata('msg','Failed to send password, please try again!');
  98. } else {
  99. $this->session->set_flashdata('msg','Password sent to your email!');
  100. }
  101. redirect(site_url().'user/login_view','refresh');
  102. }
  103. else
  104. {
  105. $this->session->set_flashdata('msg','Email not found try again!');
  106. redirect(site_url().'user/login_view','refresh');
  107. }
  108.  
  109. }
  110.  
  111. }
  112. ?>
Add Comment
Please, Sign In to add comment