Session.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_OpenId
  17. * @subpackage Zend_OpenId_Provider
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_OpenId_Provider_User
  24. */
  25. require_once "Zend/OpenId/Provider/User.php";
  26. /**
  27. * @see Zend_Session_Namespace
  28. */
  29. require_once "Zend/Session/Namespace.php";
  30. /**
  31. * Class to get/store information about logged in user in Web Browser using
  32. * PHP session
  33. *
  34. * @category Zend
  35. * @package Zend_OpenId
  36. * @subpackage Zend_OpenId_Provider
  37. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_OpenId_Provider_User_Session extends Zend_OpenId_Provider_User
  41. {
  42. /**
  43. * Reference to an implementation of Zend_Session_Namespace object
  44. *
  45. * @var Zend_Session_Namespace $_session
  46. */
  47. private $_session = null;
  48. /**
  49. * Creates Zend_OpenId_Provider_User_Session object with given session
  50. * namespace or creates new session namespace named "openid"
  51. *
  52. * @param Zend_Session_Namespace $session
  53. */
  54. public function __construct(Zend_Session_Namespace $session = null)
  55. {
  56. if ($session === null) {
  57. $this->_session = new Zend_Session_Namespace("openid");
  58. } else {
  59. $this->_session = $session;
  60. }
  61. }
  62. /**
  63. * Stores information about logged in user in session data
  64. *
  65. * @param string $id user identity URL
  66. * @return bool
  67. */
  68. public function setLoggedInUser($id)
  69. {
  70. $this->_session->logged_in = $id;
  71. return true;
  72. }
  73. /**
  74. * Returns identity URL of logged in user or false
  75. *
  76. * @return mixed
  77. */
  78. public function getLoggedInUser()
  79. {
  80. if (isset($this->_session->logged_in)) {
  81. return $this->_session->logged_in;
  82. }
  83. return false;
  84. }
  85. /**
  86. * Performs logout. Clears information about logged in user.
  87. *
  88. * @return bool
  89. */
  90. public function delLoggedInUser()
  91. {
  92. unset($this->_session->logged_in);
  93. return true;
  94. }
  95. }