Last active
August 29, 2015 14:27
-
-
Save tranquangchau/42b82fd82e710571f590 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
/** | |
* Description of Authentication | |
* Function forgot_password | |
* forgot_password_fix recontructer forgot_password for if if if if if | |
* use http://www.codeigniter.com/user_guide/helpers/string_helper.html make random new pass work | |
* use http://www.codeigniter.com/user_guide/libraries/email.html for send email | |
* use http://php.net/manual/en/function.filter-var.php for chek correct email | |
* step 1 check email http://phpsolutionpro.blogspot.com/2013/04/codeigniter-get-your-forgotten-password.html | |
* step 2 tao pass random - help - string- http://www.codeigniter.com/user_guide/helpers/string_helper.html | |
* step 3 update database http://phpsolutionpro.blogspot.com/2013/04/codeigniter-get-your-forgotten-password_7.html | |
* step 4 send mail | |
* step 5 check mail | |
* step 6 login | |
* Step it not is for if before forgot_password_fix | |
* @author JTec-QuangChau | |
*/ | |
class Authentication extends My_Controller { | |
//put your code here | |
public function __construct() { | |
parent::__construct(); | |
$this->lang->load('content_back'); | |
} | |
public function forgot_password() { | |
$data = array(); | |
if ($this->input->method() == 'post') { | |
if ($this->input->post() != NULL) { | |
if ($this->input->post('email') != NULL) { | |
$email = $this->input->post('email'); | |
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
$this->load->model('Account_model'); | |
$result_model = $this->Account_model->forgot_pass_model($email); | |
if ($result_model) { | |
//send mail | |
$this->load->helper('string'); | |
$pass_new = random_string('alnum', 8); | |
$this->load->model('Account_model'); | |
$data_result = $this->Account_model->update_pass_email($email, $pass_new); | |
if ($data_result) { | |
$config = Array( | |
'protocol' => 'smtp', | |
'smtp_host' => 'ssl://smtp.googlemail.com', | |
'smtp_port' => 465, | |
'smtp_user' => 'test.****[email protected]', // change it to yours | |
'smtp_pass' => 'jtec****', // change it to yours it is password login gmail must success | |
'mailtype' => 'html', | |
'charset' => 'iso-8859-1', | |
'wordwrap' => TRUE | |
); | |
$this->load->library('email', $config); | |
$this->email->set_newline("\r\n"); | |
$this->email->from('test.****[email protected]'); // change it to yours | |
$this->email->to($email); // change it to yours | |
$this->email->subject('test_subject from localhost/blog'); | |
$filename = 'D:/info.png'; | |
$this->email->attach($filename); | |
$message = 'Password is ' . $pass_new; | |
$this->email->message($message); | |
if ($this->email->send()) { | |
$data['message']['sucess'] = 'System have send mail to ' . $email; | |
} else { | |
show_error($this->email->print_debugger()); | |
} | |
} else { | |
$data['message']['error'] = 'Error when save database'; | |
} | |
} else { | |
$data['message']['error'] = 'Email check in database incorrect'; | |
} | |
} else { | |
$data['message']['error'] = 'Not is address email'; | |
} | |
} else { | |
$data['message']['error'] = 'Not empty email'; | |
} | |
} else { | |
//load view | |
} | |
} | |
$this->breadcrumbs->push($this->lang->line('home'), '/back_end/authentication/home'); | |
$this->breadcrumbs->push($this->lang->line('forgot_p_breadcrum'), '/back_end/authentication/forget_password'); | |
$data['content'] = 'back_end/forgot_pass_view'; | |
$this->load->view('layout_back_end_view', $data); | |
} | |
public function forgot_password_fix() { | |
$data = array(); | |
if ($this->input->method() == 'post') { | |
$step1 = true; | |
} | |
if ($this->input->post('email') != NULL) { | |
$step2 = true; | |
} else { | |
$data['message']['error'] = 'Not empty email'; | |
} | |
if ($this->input->post() != NULL) { | |
$step3 = true; | |
} else { | |
//load view | |
} | |
$email = $this->input->post('email'); | |
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
$step4 = true; | |
} else { | |
$data['message']['error'] = 'Not is address email'; | |
} | |
if ($step1 && $step2 && $step3 && $step4) { | |
$this->load->model('Account_model'); | |
$result_model = $this->Account_model->forgot_pass_model($email); | |
if ($result_model) { | |
//send mail | |
$this->load->helper('string'); | |
$pass_new = random_string('alnum', 8); | |
$this->load->model('Account_model'); | |
$data_result = $this->Account_model->update_pass_email($email, $pass_new); | |
if ($data_result) { | |
$config = Array( | |
'protocol' => 'smtp', | |
'smtp_host' => 'ssl://smtp.googlemail.com', | |
'smtp_port' => 465, | |
'smtp_user' => '[email protected]', // change it to yours | |
'smtp_pass' => 'jtec1234', // change it to yours | |
'mailtype' => 'html', | |
'charset' => 'iso-8859-1', | |
'wordwrap' => TRUE | |
); | |
$this->load->library('email', $config); | |
$this->email->set_newline("\r\n"); | |
$this->email->from('test.****[email protected]'); // change it to yours | |
$this->email->to($email); // change it to yours | |
$this->email->subject('test_subject from localhost/blog'); | |
$filename = 'D:/info.png'; | |
$this->email->attach($filename); | |
$message = 'Password is ' . $pass_new; | |
$this->email->message($message); | |
if ($this->email->send()) { | |
$data['message']['sucess'] = 'System have send mail to ' . $email; | |
} else { | |
show_error($this->email->print_debugger()); | |
} | |
} else { | |
$data['message']['error'] = 'Error when save database'; | |
} | |
} else { | |
$data['message']['error'] = 'Email check in database incorrect'; | |
} | |
} | |
$this->breadcrumbs->push($this->lang->line('home'), '/back_end/authentication/home'); | |
$this->breadcrumbs->push($this->lang->line('forgot_p_breadcrum'), '/back_end/authentication/forget_password'); | |
$data['content'] = 'back_end/forgot_pass_view'; | |
$this->load->view('layout_back_end_view', $data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment