diff options
Diffstat (limited to 'lib/private/Authentication/Token/DefaultTokenMapper.php')
-rw-r--r-- | lib/private/Authentication/Token/DefaultTokenMapper.php | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/private/Authentication/Token/DefaultTokenMapper.php b/lib/private/Authentication/Token/DefaultTokenMapper.php index 35989d0d350..9a73192c0d8 100644 --- a/lib/private/Authentication/Token/DefaultTokenMapper.php +++ b/lib/private/Authentication/Token/DefaultTokenMapper.php @@ -22,6 +22,7 @@ namespace OC\Authentication\Token; +use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\Mapper; use OCP\IDBConnection; @@ -31,6 +32,37 @@ class DefaultTokenMapper extends Mapper { parent::__construct($db, 'authtoken'); } + /** + * Invalidate (delete) a given token + * + * @param string $token + */ + public function invalidate($token) { + $sql = 'DELETE FROM `' . $this->getTableName() . '` ' + . 'WHERE `token` = ?'; + return $this->execute($sql, [ + $token + ]); + } + + /** + * @param int $olderThan + */ + public function invalidateOld($olderThan) { + $sql = 'DELETE FROM `' . $this->getTableName() . '` ' + . 'WHERE `last_activity` < ?'; + $this->execute($sql, [ + $olderThan + ]); + } + + /** + * Get the user UID for the given token + * + * @param string $token + * @throws DoesNotExistException + * @return string + */ public function getTokenUser($token) { $sql = 'SELECT `uid` ' . 'FROM `' . $this->getTableName() . '` ' |