Advertisement
azmicolejr

Untitled

May 15th, 2018
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.63 KB | None | 0 0
  1. public function forgot_password(){
  2.   // setting validation rules by checking whether identity is identity or email
  3.   if($this->config->item('identity', 'ion_auth') != 'email' ){
  4.     $this->form_validation->set_rules('identity', $this->lang->line('forgot_password_username_label'), 'required');
  5.   }
  6.     else{
  7.       $this->form_validation->set_rules('identity', $this->lang->line('forgot_password_validation_email_label'), 'required|valid_email');
  8.     }
  9.  
  10.   if ($this->form_validation->run() == false){
  11.     $this->data['type'] = $this->config->item('identity','ion_auth');
  12.     // setup the input
  13.     $this->data['identity'] = array('name' => 'identity',
  14.       'id' => 'identity',
  15.     );
  16.  
  17.     if ( $this->config->item('identity', 'ion_auth') != 'email' ){
  18.       $this->data['username_label'] = $this->lang->line('forgot_password_username_label');
  19.     }
  20.       else{
  21.         $this->data['username_label'] = $this->lang->line('forgot_password_email_username_label');
  22.       }
  23.  
  24.       // set any errors and display the form
  25.       $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
  26.       $this->_render_page('back/auth/forgot_password', $this->data);
  27.   }
  28.     else{
  29.       $identity_column = $this->config->item('identity','ion_auth');
  30.       $identity = $this->ion_auth->where($identity_column, $this->input->post('identity'))->users()->row();
  31.  
  32.       if(empty($identity)) {
  33.         if($this->config->item('identity', 'ion_auth') != 'email'){
  34.           $this->ion_auth->set_error('forgot_password_username_not_found');
  35.         }
  36.           else{
  37.             $this->ion_auth->set_error('forgot_password_email_not_found');
  38.           }
  39.  
  40.         $this->session->set_flashdata('message', $this->ion_auth->errors());
  41.         redirect("admin/auth/forgot_password", 'refresh');
  42.       }
  43.  
  44.       // run the forgotten password method to email an activation code to the user
  45.       $forgotten = $this->ion_auth->forgotten_password($identity->{$this->config->item('identity', 'ion_auth')});
  46.       if ($forgotten){
  47.         $config = [
  48.              'smtp_host' => 'ssl://smtp.gmail.com',
  49.              'smtp_user' => 'azmicolejr@gmail.com',   // Ganti dengan email gmail Anda.
  50.              'smtp_pass' => 'password',             // Password gmail Anda.
  51.              'smtp_port' => 465,
  52.              'mailtype' => 'html',
  53.         ];
  54.  
  55.         // Pengirim dan penerima email.
  56.         $this->email->from('no-reply@azmicolejr.com', 'no-reply');    // Email dan nama pegirim.
  57.         $this->email->to($forgotten['identity']);                       // Penerima email.
  58.  
  59.         $data = array(
  60.           'identity'=>$forgotten['identity'],
  61.           'forgotten_password_code' => $forgotten['forgotten_password_code'],
  62.         );
  63.  
  64.         // Load library email dan konfigurasinya.
  65.         $this->load->library('email');
  66.         $this->email->initialize($config);
  67.  
  68.         // Subject email.
  69.         $this->email->subject('Permintaan Lupa Password');
  70.  
  71.         // Isi email. Bisa dengan format html.
  72.         $body = $this->load->view('back/auth/email/forgot_password.tpl.php',$data,TRUE);
  73.         $this->email->message($body);
  74.  
  75.         if ($this->email->send()) {
  76.           $this->session->set_flashdata('message',$this->ion_auth->messages());
  77.           redirect('admin/auth/login');
  78.         }
  79.         else {
  80.           $this->session->set_flashdata('message', $this->ion_auth->errors());
  81.           redirect('admin/auth/login');
  82.         }
  83.       }
  84.         else{
  85.           $this->session->set_flashdata('message', $this->ion_auth->errors());
  86.           redirect("admin/auth/forgot_password", 'refresh');
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement