session = session(); $this->MemberModel = new Member_model(); $this->UserModel = new User_model(); $this->dModel = new Dashboard_model(); $this->cModel = new Common_model(); $this->creditsModel = new Member_credits_model(); $this->PackagesModel = new Packages_and_pricing_model(); $this->CreditsUsageTrackingModel = new Credits_usage_tracking_model(); $this->MailModel = new Email_template_model(); helper(['form', 'url']); } public function index($to,$code,$return) { $email = \Config\Services::email(); $email->setFrom('suseendhiran.1702117@srit.org', 'suseendhiran'); $email->setTo($to); // login user change passowrd => type 4 if($return == 4) { $data['id'] = '4'; $mem_data = $this->MemberModel->where('email', $to)->find(); if ($mem_data) { $temp_data = $this->MailModel->where('type' , 4)->where('is_active' , 1)->find(); if ($temp_data[0]['to']) $email->setCC($temp_data[0]['to']); if ($temp_data) { $data['html'] = str_replace("%name%",$mem_data[0]['name'],$temp_data[0]['html']); } $message = view('verification_mail_temp',$data); if ($temp_data[0]['is_active'] == 1) $email->setSubject($temp_data[0]['subject']); else $email->setSubject('Password change'); } else { $user_data = $this->UserModel->where('email', $to)->find(); $temp_data = $this->MailModel->where('type' , 4)->where('is_active' , 1)->find(); if ($temp_data[0]['to']) $email->setCC($temp_data[0]['to']); if ($temp_data) { $data['html'] = str_replace("%name%",$user_data[0]['name'],$temp_data[0]['html']); } $message = view('verification_mail_temp',$data); } $message = view('verification_mail_temp',$data); if ($temp_data[0]['is_active'] == 1) $email->setSubject($temp_data[0]['subject']); else $email->setSubject('Password change'); } // user => type 2 else if($return == 3) { $user_data = $this->UserModel->where('email', $to)->find(); $data['id'] = '3'; $data['username'] = $to; $data['password'] = $code; $data['url'] = base_url()."admin"; $temp_data = $this->MailModel->where('type' , 2)->where('is_active' , 1)->find(); if ($temp_data[0]['to']) $email->setCC($temp_data[0]['to']); if ($temp_data) $data['html'] = str_replace("%name%",$user_data[0]['name'],$temp_data[0]['html']); $message = view('verification_mail_temp',$data); if ($temp_data[0]['is_active'] == 1) $email->setSubject($temp_data[0]['subject']); else $email->setSubject('Username Password'); } // otp => type 3 else if ($return == 2) { $data['id'] = '2'; $data['otp'] = $code; $mem_data = $this->MemberModel->where('email', $to)->find(); if ($mem_data) { $temp_data = $this->MailModel->where('type' , 3)->where('is_active' , 1)->find(); if ($temp_data[0]['to']) $email->setCC($temp_data[0]['to']); if ($temp_data) { $html = str_replace("%name%",$mem_data[0]['name'],$temp_data[0]['html']); $data['html'] = str_replace("%otp%",$code,$html); } $message = view('verification_mail_temp',$data); if ($temp_data[0]['is_active'] == 1) $email->setSubject($temp_data[0]['subject']); else $email->setSubject('OTP verification'); } else { $user_data = $this->UserModel->where('email', $to)->find(); $temp_data = $this->MailModel->where('type' , 3)->where('is_active' , 1)->find(); if ($temp_data[0]['to']) $email->setCC($temp_data[0]['to']); if ($temp_data) { $html = str_replace("%name%",$user_data[0]['name'],$temp_data[0]['html']); $data['html'] = str_replace("%otp%",$code,$html); } $message = view('verification_mail_temp',$data); if ($temp_data[0]['is_active'] == 1) $email->setSubject($temp_data[0]['subject']); else $email->setSubject('OTP verification'); } } // member => type 1 else if($return == 1) { // $email->setCC('another@another-example.com'); // $email->setBCC('them@their-example.com'); $user_data = $this->MemberModel->where('email', $to)->find(); $data['to'] = $to; $data['code'] = $code; $data['url'] = base_url()."verify_email/".md5($code); $temp_data = $this->MailModel->where('type' , 1)->where('is_active' , 1)->find(); if ($temp_data[0]['to']) $email->setCC($temp_data[0]['to']); if ($temp_data) $data['html'] = str_replace("%name%",$user_data[0]['name'],$temp_data[0]['html']); $message = view('verification_mail_temp',$data); if ($temp_data[0]['is_active'] == 1) $email->setSubject($temp_data[0]['subject']); else $email->setSubject('Verify your email address'); } // $email->setMessage($message); if ($email->send()) { if ($return == 1) { $this->session->setTempdata('mail_success', "Please check your mail to verify",3); // return redirect()->to(base_url()); } } else { echo 0; } } public function verify_email($verification_code) { // Get the user data corresponding to the verification code $user_data = $this->MemberModel->where('md5(verification_code)', $verification_code)->find(); if($user_data) { //print_r($user_data);die(); if($user_data[0]['is_email_verified'] == 0) { // Update the users status // $update_data = $this->MemberModel->update_status($user_data['id']); $data['is_email_verified'] = 1; $update_data = $this->MemberModel->where('id', $user_data[0]['id'] )->set($data)->update(); if($update_data) { return redirect()->to(base_url()."set_password/".md5($user_data[0]['id'])); } else { // Show error message echo 'Error in verifying email. Please try again.'; } } else { // Show error message echo 'Email already verified.'; } } else { // Show error message echo 'Invalid verification code.'; } } public function forgot_password() { $this->session->setTempdata('user',"member",3); if($this->request->getmethod() == 'get') { return view('forgot_password.php'); } else if($this->request->getmethod() == 'post') { $email = $this->request->getVar('email'); $user_data = $this->MemberModel->where('email', $email)->where('is_email_verified', 1 )->find(); if ($user_data) { $otp = rand(1000 , 9999); $this->index($this->request->getVar('email') , $otp , 2 ); $data['status'] = 'success'; $data['otp'] = $otp; echo json_encode($data); } else { $data['status'] = 'failed'; echo json_encode($data); } } } }