Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!defined('BASEPATH'))
- exit('No direct script access allowed');
- class Login extends CI_Controller {
- function __construct() {
- parent::__construct();
- }
- function index() {
- $data['header'] = 'include/header';
- $data['body'] = 'login';
- $data['footer'] = 'include/footer';
- $this->load->view('templates/frame', $data);
- }
- function reset() {
- $data['header'] = 'include/header';
- $data['body'] = 'reset';
- $data['footer'] = 'include/footer';
- $this->load->view('templates/frame', $data);
- }
- public function email_check($email) {
- $user = $this->unit_model->get_userEmailSite_model($email);
- if (!$user) {
- $this->form_validation->set_message('email_check', 'Email does not exist.');
- return FALSE;
- } else {
- return TRUE;
- }
- }
- public function send_links() {
- $email = $this->db->escape_str($this->input->post('email'));
- $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
- $this->form_validation->set_rules('email', 'Email', 'required|valid_email|callback_email_check');
- if ($this->form_validation->run($this) == FALSE) {
- $this->reset();
- } else {
- $resetcode = random_string('alnum', 8);
- $userdata['password_reset_code'] = $resetcode;
- $this->unit_model->update_user_model($email, $userdata);
- $to = $email;
- $subject = "Here's the link to reset your password";
- $content = "
- <pre>
- Hi,
- We’ve recently received a request to make changes to your password for ???.
- Please ignore this email if it was not you, your password will not be changed.
- If you wish to change your password , please click on </pre><a href='" . base_url() . "login/change_pwd?email=" . urlencode($email) . "&tok=" . $resetcode . "'>" . base_url() . "login/change_pwd?email=" . urlencode($email) . "&tok=" . $resetcode . "</a>
- <pre>
- Sincerely
- ??? Team
- </pre>
- ";
- $message = "";
- $template = "./application/views/templates/html_email_template.php";
- if (file_exists($template)) {
- $message = file_get_contents($template);
- $replace_with = array(
- base_url() . 'assets/img/logo.png',
- $subject,
- "USER PASSWORD CHANGE REQUEST",
- $content,
- date("Y")
- );
- for ($i = 0; $i < count($replace_with); $i++) {
- $message = str_replace("[part" . $i . "]", $replace_with[$i], $message);
- }
- } else {
- foreach ($_POST as $key => $value) {
- $message .= "<p>" . $key . ": " . $value . "</p>";
- }
- }
- $headers = "MIME-Version: 1.0" . "\r\n";
- $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
- $headers .= 'From: <noreply@shriro.com.au>' . "\r\n";
- $headers .= "To: <$email>\r\n";
- $headers .= "Reply-To: noreply@shriro.com.au\r\n";
- mail($email, $subject, $message, $headers);
- $this->session->set_flashdata('info', "Email sent. We’ve sent you a link to change your password.");
- redirect(base_url() . 'login/reset');
- }
- }
- public function change_pwd() {
- $email = urldecode($this->input->get('email'));
- $tok = $this->input->get('tok');
- if (strlen($email) && strlen($tok)) {
- $user = $this->unit_model->get_userEmailSiteTok_model($email, $tok);
- if (!$user) {
- redirect(base_url() . "login/reset");
- }
- $data['email'] = $email;
- $data['tok'] = $tok;
- $data['header'] = 'include/header';
- $data['body'] = 'change_pwd';
- $data['footer'] = 'include/footer';
- $this->load->view('templates/frame', $data);
- } else {
- redirect(base_url() . "login/reset");
- }
- }
- public function loginid_check($email) {
- $this->form_validation->set_message('loginid_check', 'Wrong Email');
- return FALSE;
- }
- public function update_pwd() {
- $loginid = $this->input->post('loginid');
- $tok = $this->input->post('tok');
- $email = $this->input->post('email');
- $password = $this->input->post('password');
- if (!($loginid == $email)) {
- $this->form_validation->set_rules('username', 'Email', 'callback_loginid_check');
- } else {
- $this->form_validation->set_rules('loginid', 'Email', 'required');
- }
- $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
- $this->form_validation->set_rules('password', 'Password', 'required|alpha_numeric');
- $this->form_validation->set_rules('password_confirm', 'Password Confirm', 'required|alpha_numeric|matches[password]');
- if ($this->form_validation->run($this) == FALSE) {
- $data['email'] = $email;
- $data['tok'] = $tok;
- $data['header'] = 'include/header';
- $data['body'] = 'change_pwd';
- $data['footer'] = 'include/footer';
- $this->load->view('templates/frame', $data);
- } else {
- $userinfo = $this->unit_model->get_userEmailSite_model($loginid);
- if (!$userinfo) {
- die('access denied');
- }
- $user = $this->unit_model->get_userEmailSiteTok_model($userinfo[0]->email, $tok);
- if (!$user) {
- die('access denied');
- }
- $pwd_data['password'] = password_hash($password, PASSWORD_DEFAULT);
- $pwd_data['password_reset_code'] = null;
- $this->unit_model->update_user_model($userinfo[0]->email, $pwd_data);
- $this->session->set_flashdata('info', "New password has been successfully updated.");
- redirect(base_url() . "login");
- }
- }
- function logout() {
- $this->unit_model->userlog("logout");
- $this->session->sess_destroy();
- redirect(base_url() . "login");
- }
- function auth() {
- $email = $this->db->escape_str($this->input->post('email'));
- $password = $this->db->escape_str($this->input->post('password'));
- $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
- $this->form_validation->set_rules('email', 'Email', 'required|valid_email|callback_email_check');
- $this->form_validation->set_rules('password', 'Password', 'required|alpha_numeric');
- if ($this->form_validation->run($this) == FALSE) {
- $this->index();
- } else {
- $auth = $this->unit_model->auth_model($email);
- if (password_verify($password, $auth[0]->password)) {
- $company = $this->unit_model->get_unit_model("heston_company", array('id =' => $auth[0]->company_id));
- $logged_in_data['uid'] = $auth[0]->id;
- $logged_in_data['email'] = $auth[0]->email;
- $logged_in_data['fname'] = $auth[0]->first_name;
- $logged_in_data['lname'] = $auth[0]->last_name;
- $logged_in_data['level'] = $auth[0]->access_level;
- $logged_in_data['company'] = $company[0]->name;
- $logged_in_data['cid'] = $auth[0]->company_id;
- $this->session->set_userdata('logged_in_data', $logged_in_data);
- $this->session->set_userdata('location', 0);
- $this->unit_model->userlog("login");
- redirect(base_url() . "dashboard");
- } else {
- $this->session->set_flashdata('error', "Wrong login combination.");
- redirect(base_url() . 'login');
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement