Advertisement
wolfgang1983

Customer Autologin

Jul 28th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. <?php
  2.  
  3. class Customer {
  4.  
  5. public function __construct() {
  6. $this->CI = &get_instance();
  7. $this->CI->load->library('encryption');
  8. $this->CI->load->library('encrypt');
  9. $this->CI->load->library('session');
  10. $this->CI->load->helper('string');
  11. $this->CI->load->model('customer_model');
  12.  
  13. if (!$this->is_logged_in('is_logged_in')) {
  14. $this->authenticateAutologin();
  15. }
  16. }
  17.  
  18. public function postLogin() {
  19. $customer_query = $this->CI->customer_model->get_customer();
  20.  
  21. if ($customer_query) {
  22.  
  23. $login_session_data = array(
  24. 'customer_id' => $customer_query['customer_id'],
  25. 'is_logged_in' => true
  26. );
  27.  
  28. $this->CI->session->set_userdata($login_session_data);
  29.  
  30. if ($this->CI->input->post('remember', true)) {
  31. // Create A Autologin.
  32. }
  33.  
  34. return true;
  35. }
  36. }
  37.  
  38. public function is_logged_in() {
  39. return $this->CI->session->userdata('is_logged_in');
  40. }
  41.  
  42. public function authenticateAutologin() {
  43.  
  44. // @todo proper auth encrypt
  45.  
  46. $autologinData = $this->readAutologin();
  47.  
  48. if ($autologinData) {
  49.  
  50. $autologinSessionData = array(
  51. 'customer_id' => $autologinData['customer_id'],
  52. 'is_logged_in' => true,
  53. 'autologin' => 'enabled'
  54. );
  55.  
  56. $this->CI->session->set_userdata($autologinSessionData);
  57.  
  58. return true;
  59.  
  60. }
  61.  
  62. return false;
  63. }
  64.  
  65. public function readAutologin() {
  66. $this->CI->db->where('customer_id', '1');
  67. $query = $this->CI->db->get($this->CI->db->dbprefix . 'customer_autologin');
  68. if ($query->num_rows() == 1) {
  69. return $query->row_array();
  70. } else {
  71. return false;
  72. }
  73. }
  74.  
  75. public function logout()
  76. {
  77. $this->CI->session->unset_userdata('is_logged_in');
  78. $this->CI->session->unset_userdata('customer_id');
  79. $this->CI->session->unset_userdata('autologin');
  80. setcookie('remember', '', $this->CI->config->item('end_cookie_time'), '/');
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement