Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Customer {
- public function __construct() {
- $this->CI = &get_instance();
- $this->CI->load->library('encryption');
- $this->CI->load->library('encrypt');
- $this->CI->load->library('session');
- $this->CI->load->helper('string');
- $this->CI->load->model('customer_model');
- if (!$this->is_logged_in('is_logged_in')) {
- $this->authenticateAutologin();
- }
- }
- public function postLogin() {
- $customer_query = $this->CI->customer_model->get_customer();
- if ($customer_query) {
- $login_session_data = array(
- 'customer_id' => $customer_query['customer_id'],
- 'is_logged_in' => true
- );
- $this->CI->session->set_userdata($login_session_data);
- if ($this->CI->input->post('remember', true)) {
- // Create A Autologin.
- }
- return true;
- }
- }
- public function is_logged_in() {
- return $this->CI->session->userdata('is_logged_in');
- }
- public function authenticateAutologin() {
- // @todo proper auth encrypt
- $autologinData = $this->readAutologin();
- if ($autologinData) {
- $autologinSessionData = array(
- 'customer_id' => $autologinData['customer_id'],
- 'is_logged_in' => true,
- 'autologin' => 'enabled'
- );
- $this->CI->session->set_userdata($autologinSessionData);
- return true;
- }
- return false;
- }
- public function readAutologin() {
- $this->CI->db->where('customer_id', '1');
- $query = $this->CI->db->get($this->CI->db->dbprefix . 'customer_autologin');
- if ($query->num_rows() == 1) {
- return $query->row_array();
- } else {
- return false;
- }
- }
- public function logout()
- {
- $this->CI->session->unset_userdata('is_logged_in');
- $this->CI->session->unset_userdata('customer_id');
- $this->CI->session->unset_userdata('autologin');
- setcookie('remember', '', $this->CI->config->item('end_cookie_time'), '/');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement