diff options
Diffstat (limited to 'lib/private/Authentication/Token/DefaultToken.php')
-rw-r--r-- | lib/private/Authentication/Token/DefaultToken.php | 123 |
1 files changed, 75 insertions, 48 deletions
diff --git a/lib/private/Authentication/Token/DefaultToken.php b/lib/private/Authentication/Token/DefaultToken.php index e06803d0bfc..85ea0dc4cdd 100644 --- a/lib/private/Authentication/Token/DefaultToken.php +++ b/lib/private/Authentication/Token/DefaultToken.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @@ -28,82 +29,76 @@ use OCP\AppFramework\Db\Entity; /** * @method void setId(int $id) * @method void setUid(string $uid); - * @method void setLoginName(string $loginName) - * @method void setPassword(string $password) + * @method void setLoginName(string $loginname) * @method void setName(string $name) - * @method string getName() - * @method void setToken(string $token) * @method string getToken() - * @method void setType(string $type) + * @method void setType(int $type) * @method int getType() * @method void setRemember(int $remember) - * @method int getRemember() - * @method void setLastActivity(int $lastActivity) + * @method void setLastActivity(int $lastactivity) * @method int getLastActivity() + * @method void setVersion(int $version) */ class DefaultToken extends Entity implements IToken { - /** - * @var string user UID - */ + const VERSION = 1; + + /** @var string user UID */ protected $uid; - /** - * @var string login name used for generating the token - */ + /** @var string login name used for generating the token */ protected $loginName; - /** - * @var string encrypted user password - */ + /** @var string encrypted user password */ protected $password; - /** - * @var string token name (e.g. browser/OS) - */ + /** @var string token name (e.g. browser/OS) */ protected $name; - /** - * @var string - */ + /** @var string */ protected $token; - /** - * @var int - */ + /** @var int */ protected $type; - /** - * @var int - */ + /** @var int */ protected $remember; - /** - * @var int - */ + /** @var int */ protected $lastActivity; - /** - * @var int - */ + /** @var int */ protected $lastCheck; - /** - * @var string - */ + /** @var string */ protected $scope; + /** @var int */ + protected $expires; + + /** @var int */ + protected $version; + public function __construct() { + $this->addType('uid', 'string'); + $this->addType('loginName', 'string'); + $this->addType('password', 'string'); + $this->addType('name', 'string'); + $this->addType('token', 'string'); $this->addType('type', 'int'); + $this->addType('remember', 'int'); $this->addType('lastActivity', 'int'); $this->addType('lastCheck', 'int'); + $this->addType('scope', 'string'); + $this->addType('expires', 'int'); + $this->addType('version', 'int'); } - public function getId() { + public function getId(): int { return $this->id; } - public function getUID() { + public function getUID(): string { return $this->uid; } @@ -112,14 +107,14 @@ class DefaultToken extends Entity implements IToken { * * @return string */ - public function getLoginName() { + public function getLoginName(): string { return parent::getLoginName(); } /** * Get the (encrypted) login password * - * @return string + * @return string|null */ public function getPassword() { return parent::getPassword(); @@ -140,7 +135,7 @@ class DefaultToken extends Entity implements IToken { * * @return int */ - public function getLastCheck() { + public function getLastCheck(): int { return parent::getLastCheck(); } @@ -149,15 +144,20 @@ class DefaultToken extends Entity implements IToken { * * @param int $time */ - public function setLastCheck($time) { - return parent::setLastCheck($time); + public function setLastCheck(int $time) { + parent::setLastCheck($time); } - public function getScope() { - return parent::getScope(); + public function getScope(): string { + $scope = parent::getScope(); + if ($scope === null) { + return ''; + } + + return $scope; } - public function getScopeAsArray() { + public function getScopeAsArray(): array { $scope = json_decode($this->getScope(), true); if (!$scope) { return [ @@ -168,10 +168,37 @@ class DefaultToken extends Entity implements IToken { } public function setScope($scope) { - if (is_array($scope)) { + if (\is_array($scope)) { parent::setScope(json_encode($scope)); } else { parent::setScope((string)$scope); } } + + public function getName(): string { + return parent::getName(); + } + + public function getRemember(): int { + return parent::getRemember(); + } + + public function setToken(string $token) { + parent::setToken($token); + } + + public function setPassword(string $password = null) { + parent::setPassword($password); + } + + public function setExpires($expires) { + parent::setExpires($expires); + } + + /** + * @return int|null + */ + public function getExpires() { + return parent::getExpires(); + } } |