Check token expiry

This commit is contained in:
Jarkko Toivanen 2024-09-28 18:47:40 +03:00
parent f5371aba5d
commit 261816fa4e
Signed by: jt
GPG key ID: 9151B109B73ECAD5

View file

@ -169,11 +169,15 @@ class DataBase extends SQLite3 {
$token = base64_decode($_COOKIE['token']); $token = base64_decode($_COOKIE['token']);
} }
$hashed = hash('sha256', $token); $hashed = hash('sha256', $token);
$sql = "SELECT id AS id, userid AS userid FROM tokens WHERE token='$hashed';"; $sql = "SELECT id AS id, userid AS userid, expires AS expires FROM tokens WHERE token='$hashed';";
$ret = $this->query($sql)->fetchArray(SQLITE3_ASSOC); $ret = $this->query($sql)->fetchArray(SQLITE3_ASSOC);
if(!$ret) { if(!$ret) {
return false; return false;
} }
if ($ret['expires'] < time()) {
$this->tokenRemove($token);
return false;
}
$this->tokenRefresh($ret['id']); $this->tokenRefresh($ret['id']);
return $ret['userid']; return $ret['userid'];
} }