Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function forgot_password(){
- // setting validation rules by checking whether identity is identity or email
- if($this->config->item('identity', 'ion_auth') != 'email' ){
- $this->form_validation->set_rules('identity', $this->lang->line('forgot_password_username_label'), 'required');
- }
- else{
- $this->form_validation->set_rules('identity', $this->lang->line('forgot_password_validation_email_label'), 'required|valid_email');
- }
- if ($this->form_validation->run() == false){
- $this->data['type'] = $this->config->item('identity','ion_auth');
- // setup the input
- $this->data['identity'] = array('name' => 'identity',
- 'id' => 'identity',
- );
- if ( $this->config->item('identity', 'ion_auth') != 'email' ){
- $this->data['username_label'] = $this->lang->line('forgot_password_username_label');
- }
- else{
- $this->data['username_label'] = $this->lang->line('forgot_password_email_username_label');
- }
- // set any errors and display the form
- $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
- $this->_render_page('back/auth/forgot_password', $this->data);
- }
- else{
- $identity_column = $this->config->item('identity','ion_auth');
- $identity = $this->ion_auth->where($identity_column, $this->input->post('identity'))->users()->row();
- if(empty($identity)) {
- if($this->config->item('identity', 'ion_auth') != 'email'){
- $this->ion_auth->set_error('forgot_password_username_not_found');
- }
- else{
- $this->ion_auth->set_error('forgot_password_email_not_found');
- }
- $this->session->set_flashdata('message', $this->ion_auth->errors());
- redirect("admin/auth/forgot_password", 'refresh');
- }
- // run the forgotten password method to email an activation code to the user
- $forgotten = $this->ion_auth->forgotten_password($identity->{$this->config->item('identity', 'ion_auth')});
- if ($forgotten){
- $config = [
- 'smtp_host' => 'ssl://smtp.gmail.com',
- 'smtp_user' => 'azmicolejr@gmail.com', // Ganti dengan email gmail Anda.
- 'smtp_pass' => 'password', // Password gmail Anda.
- 'smtp_port' => 465,
- 'mailtype' => 'html',
- ];
- // Pengirim dan penerima email.
- $this->email->from('no-reply@azmicolejr.com', 'no-reply'); // Email dan nama pegirim.
- $this->email->to($forgotten['identity']); // Penerima email.
- $data = array(
- 'identity'=>$forgotten['identity'],
- 'forgotten_password_code' => $forgotten['forgotten_password_code'],
- );
- // Load library email dan konfigurasinya.
- $this->load->library('email');
- $this->email->initialize($config);
- // Subject email.
- $this->email->subject('Permintaan Lupa Password');
- // Isi email. Bisa dengan format html.
- $body = $this->load->view('back/auth/email/forgot_password.tpl.php',$data,TRUE);
- $this->email->message($body);
- if ($this->email->send()) {
- $this->session->set_flashdata('message',$this->ion_auth->messages());
- redirect('admin/auth/login');
- }
- else {
- $this->session->set_flashdata('message', $this->ion_auth->errors());
- redirect('admin/auth/login');
- }
- }
- else{
- $this->session->set_flashdata('message', $this->ion_auth->errors());
- redirect("admin/auth/forgot_password", 'refresh');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement