Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class user_model extends CI_model{
- public function register_user($user){
- $this->db->insert('user', $user);
- }
- public function login_user($email,$pass,$status,$level){
- $this->db->select('*');
- $this->db->from('user');
- $this->db->where('email',$email);
- $this->db->where('password',$pass);
- $this->db->where('status',$status);
- $this->db->where('level',$level);
- if($query=$this->db->get())
- {
- return $query->row_array();
- }
- else{
- return false;
- }
- }
- public function email_check($email){
- $this->db->select('*');
- $this->db->from('user');
- $this->db->where('email',$email);
- $query=$this->db->get();
- if($query->num_rows()>0){
- return false;
- }else{
- return true;
- }
- }
- //funtion to get email of user to send password
- public function ForgotPassword($email)
- {
- $this->db->select('email');
- $this->db->from('user');
- $this->db->where('email', $email);
- $query=$this->db->get();
- return $query->row_array();
- }
- public function sendpassword($data)
- {
- $email = $data['email'];
- $query1=$this->db->query("SELECT * from user where email = '".$email."' ");
- $row=$query1->result_array();
- if ($query1->num_rows()>0)
- {
- $passwordplain = "";
- $passwordplain = rand(999999999,9999999999);
- $newpass['password'] = md5($passwordplain);
- $this->db->where('email', $email);
- $this->db->update('user', $newpass);
- $mail_message='Dear '.$row[0]['fname'].','. "\r\n";
- $mail_message.='Thanks for contacting regarding to forgot password,<br> Your <b>Password</b> is <b>'.$passwordplain.'</b>'."\r\n";
- $mail_message.='<br>Please Update your password.';
- $mail_message.='<br>Thanks & Regards';
- $mail_message.='<br>Your company name';
- date_default_timezone_set('Etc/UTC');
- require FCPATH.'assets/PHPMailer/PHPMailerAutoload.php';
- $mail = new PHPMailer;
- $mail->isSMTP();
- $mail->SMTPSecure = "tls";
- $mail->Debugoutput = 'html';
- $mail->Host = "yooursmtp";
- $mail->Port = 587;
- $mail->SMTPAuth = true;
- $mail->Username = "your@email.com";
- $mail->Password = "password";
- $mail->setFrom('admin@site', 'admin');
- $mail->IsHTML(true);
- $mail->addAddress($email);
- $mail->Subject = 'OTP from company';
- $mail->Body = $mail_message;
- $mail->AltBody = $mail_message;
- if (!$mail->send()) {
- $this->session->set_flashdata('msg','Failed to send password, please try again!');
- } else {
- $this->session->set_flashdata('msg','Password sent to your email!');
- }
- redirect(site_url().'user/login_view','refresh');
- }
- else
- {
- $this->session->set_flashdata('msg','Email not found try again!');
- redirect(site_url().'user/login_view','refresh');
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment