Guest User

Untitled

a guest
May 25th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <?php
  2.  
  3. // *****************************************************************************
  4. // Capital IT Inc.
  5. // Copyright (C) 2008. All Rights Reserved
  6. //
  7. // $Source: /cvsroot/smn/app/lib/user/SMNUser.class.php,v $
  8. // $Revision: 1.1 $
  9. // $Date: 2008/11/02 23:46:43 $
  10. // $Author: btiernay $
  11. //
  12. // *****************************************************************************
  13.  
  14. class SMNUser extends AgaviRbacSecurityUser {
  15. public function startup() {
  16. parent::startup ();
  17.  
  18. $rq = $this->getContext()->getRequest();
  19. $rd = $rq->getRequestData();
  20. if (!$this->isAuthenticated() && $rd->hasCookie('autologon')) {
  21. $login = $rd->getCookie('autologon');
  22. try {
  23. $this->login ($login['username'], $login ['password'], true);
  24. } catch (AgaviSecurityException $e) {
  25. $response = $this->getContext()->getController()->getGlobalResponse();
  26.  
  27. // Login didn't work, the cookie is invalid so delete it
  28. $response->setCookie('autologon[username]', false);
  29. $response->setCookie('autologon[password]', false);
  30. }
  31. }
  32. }
  33.  
  34. public function login($username, $password, $isPasswordHashed = true) {
  35. $um = $this->context->getModel('Users', 'Default');
  36. $user = $um->getUserByEmail($username);
  37. if (!isset($user)) {
  38. throw new AgaviSecurityException('Invalid username or password');
  39. }
  40. if ($isPasswordHashed) {
  41. $password = md5($password);
  42. }
  43. if ($password != $user['password']) {
  44. throw new AgaviSecurityException('Invalid username or password');
  45. }
  46. $user['last_login_date'] = $um->updateLogin($user);
  47. $this->setAttribute('user', $user);
  48. $this->setAuthenticated(true);
  49. $this->clearCredentials();
  50. }
  51.  
  52. public function logout() {
  53. $this->clearCredentials();
  54. $this->setAuthenticated(false);
  55. }
  56. }
  57.  
  58. ?>
Add Comment
Please, Sign In to add comment