Advertisement
Guest User

Untitled

a guest
May 4th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. <?php
  2.  
  3. class UserAuth extends AgaviRbacSecurityUser
  4. {
  5. protected $user = array();
  6.  
  7. public function startup()
  8. {
  9. // call parent
  10. parent::startup();
  11.  
  12. $reqData = $this->getContext()->getRequest()->getRequestData();
  13.  
  14. if(!$this->isAuthenticated() && $reqData->hasCookie('autologon')) {
  15. $login = $reqData->getCookie('autologon');
  16.  
  17. try {
  18. $this->login($login['username'], $login['password'], true);
  19. } catch(AgaviSecurityException $e) {
  20. $response = $this->getContext()->getController()->getGlobalResponse();
  21.  
  22. // Unset the the login cookie since it didn't work
  23. $response->setCookie('autologon[username]', false);
  24. $response->setCookie('autologon[password]', false);
  25. }
  26. }
  27. }
  28.  
  29. public function login($username, $password, $isPasswordHashed = false)
  30. {
  31. $loginsys = $this->getContext()->getModel('LoginSystem', 'UserAuthentication');
  32. $account = $loginsys->retrieveAccountByUsername($username);
  33. if(!$account['account_id']) {
  34. throw new AgaviSecurityException('username error');
  35. }
  36.  
  37. if(!$isPasswordHashed) {
  38. $password = sha1($password . $account['pass_salt']);
  39. }
  40.  
  41. if($password != trim($account['account_password'])) {
  42. throw new AgaviSecurityException('password error');
  43. }
  44.  
  45. $this->setAttribute('id', $account['account_id'], 'org.authentication.user');
  46.  
  47. $this->setAuthenticated(true);
  48. $this->grantRoles($loginsys->retrieveUserRolesByUserId($account['account_id']));
  49.  
  50. $this->user = $account; <--set array
  51. return true;
  52. }
  53.  
  54. public function logout()
  55. {
  56. $this->clearCredentials();
  57. $this->setAuthenticated(false);
  58. }
  59.  
  60. public function getCurrentUser()
  61. {
  62. if ($this->isAuthenticated()) {
  63. var_dump($this->user); die(); <----null
  64. return $this->user;
  65. }
  66. }
  67. }
  68.  
  69. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement