diff options
Diffstat (limited to 'src/Models/Tokens.php')
| -rw-r--r-- | src/Models/Tokens.php | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/Models/Tokens.php b/src/Models/Tokens.php index 4ad8e1d..ee912fb 100644 --- a/src/Models/Tokens.php +++ b/src/Models/Tokens.php @@ -37,9 +37,9 @@ class Tokens implements ConnectsToDatabase $isExpiredSql = ""; if ($isExpired) { - $isExpiredSql = "and expires_at <= current_timestamp"; + #$isExpiredSql = "and expires_at <= current_timestamp"; } else { - $isExpiredSql = "and expires_at > current_timestamp"; + #$isExpiredSql = "and expires_at > current_timestamp"; } $row = []; @@ -78,6 +78,26 @@ class Tokens implements ConnectsToDatabase public static function fetchAll(): array {} + public static function fetchWithAccessToken(string $accessToken): ?self + { + $row = Database::getInstance()->query( + <<<SQL + select * from tokens + where access_token=:access_token + order by created_at desc + SQL, + [ + "access_token" => $accessToken, + ] + )->fetch(); + + if (empty($row)) { + return null; + } + + return self::fromDatabase($row); + } + public static function fetchWithRefreshToken(string $refreshToken): ?self { $row = Database::getInstance()->query( @@ -140,6 +160,11 @@ class Tokens implements ConnectsToDatabase ); } + public function isExpired(): bool + { + return $this->expiresAt->format("U.v") <= time(); + } + public function getAccessToken(): string { return $this->accessToken; |
