DefaultToken.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * @author Christoph Wurst <christoph@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OC\Authentication\Token;
  22. use OCP\AppFramework\Db\Entity;
  23. /**
  24. * @method void setId(int $id)
  25. * @method void setUid(string $uid);
  26. * @method void setLoginName(string $loginName)
  27. * @method void setPassword(string $password)
  28. * @method void setName(string $name)
  29. * @method string getName()
  30. * @method void setToken(string $token)
  31. * @method string getToken()
  32. * @method void setType(string $type)
  33. * @method int getType()
  34. * @method void setLastActivity(int $lastActivity)
  35. * @method int getLastActivity()
  36. */
  37. class DefaultToken extends Entity implements IToken {
  38. /**
  39. * @var string user UID
  40. */
  41. protected $uid;
  42. /**
  43. * @var string login name used for generating the token
  44. */
  45. protected $loginName;
  46. /**
  47. * @var string encrypted user password
  48. */
  49. protected $password;
  50. /**
  51. * @var string token name (e.g. browser/OS)
  52. */
  53. protected $name;
  54. /**
  55. * @var string
  56. */
  57. protected $token;
  58. /**
  59. * @var int
  60. */
  61. protected $type;
  62. /**
  63. * @var int
  64. */
  65. protected $lastActivity;
  66. /**
  67. * @var int
  68. */
  69. protected $lastCheck;
  70. public function getId() {
  71. return $this->id;
  72. }
  73. public function getUID() {
  74. return $this->uid;
  75. }
  76. /**
  77. * Get the login name used when generating the token
  78. *
  79. * @return string
  80. */
  81. public function getLoginName() {
  82. return parent::getLoginName();
  83. }
  84. /**
  85. * Get the (encrypted) login password
  86. *
  87. * @return string
  88. */
  89. public function getPassword() {
  90. return parent::getPassword();
  91. }
  92. public function jsonSerialize() {
  93. return [
  94. 'id' => $this->id,
  95. 'name' => $this->name,
  96. 'lastActivity' => $this->lastActivity,
  97. 'type' => $this->type,
  98. ];
  99. }
  100. /**
  101. * Get the timestamp of the last password check
  102. *
  103. * @return int
  104. */
  105. public function getLastCheck() {
  106. return parent::getLastCheck();
  107. }
  108. /**
  109. * Get the timestamp of the last password check
  110. *
  111. * @param int $time
  112. */
  113. public function setLastCheck($time) {
  114. return parent::setLastCheck($time);
  115. }
  116. }