Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. public function mask_as_user() {
  2. $this->load->model('User_model', '', true);
  3.  
  4. $email = $this->input->post('email');
  5.  
  6. //there should be some front-end validation here too, but if not permitter, dont allow this to proceed.
  7. if (strpos($this->session->userdata('user_type'), 'permitter') === false) {
  8. $return['status'] = 'error';
  9. $return['message']= 'You are not an admin.';
  10. header('Content-type: application/json');
  11. echo json_encode($return);
  12. return false;
  13. }
  14.  
  15. //save the current admin account, so we know where to switch back to
  16. $admin_account_email = $this->session->userdata('user_email');
  17.  
  18. //logout current user to not have overlapping session data
  19. //$this->logout(false, true);
  20.  
  21. $user_data = $this->User_model->get_user_data($email);
  22.  
  23. if ($user_data[0]){
  24. $user_data = $this->clean_user_data($user_data[0]);
  25. }
  26. else{
  27. $return['status'] = 'error';
  28. $return['message']= 'This is not an active client account.';
  29. header('Content-type: application/json');
  30. echo json_encode($return);
  31. return false;
  32. }
  33. //get userdata for user-mask account and remove unneccessary data (such as login credentials) from session array
  34.  
  35. //prevent switching into admin accounts. Not really any sensitive data that the rest of the company can't access elsewhere, but maybe someday there will be.
  36. if (strpos($user_data['user_type'], 'permitter') !== false) {
  37. $return['status'] = 'error';
  38. $return['message']= 'You cannot switch into an admin account.';
  39. header('Content-type: application/json');
  40. echo json_encode($return);
  41. return false;
  42. }
  43.  
  44. //foreach column loaded from database, create a session value.
  45. $this->session->set_userdata($user_data);
  46.  
  47. //set user to loggedin.
  48. $this->session->set_userdata('loggedin', TRUE);
  49.  
  50. //set the current admin account which the mask is being applied to. We will need this for returning back to the admin account without having to logout.
  51. $this->session->set_userdata('admin_account_email', $admin_account_email);
  52.  
  53. $return['status'] = 'success';
  54. $return['redir_url'] = '/site_client/dashboard';
  55.  
  56. header('Content-type: application/json');
  57. echo json_encode($return);
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement