API Usage refreshes

This commit is contained in:
Kilian Hofmann 2024-07-29 19:33:00 +02:00
parent 053724f9b7
commit e20206d4a5
4 changed files with 31 additions and 3 deletions

View File

@ -36,6 +36,9 @@ class AdminAuth implements IMiddleware
->httpCode(401)
->json(["code" => "NotAllowed", "message" => "Not Authorized"]);
}
// Keep fresh
$user->keepFresh();
} catch (Exception $err) {
// No user with this token exists
Response::response()

View File

@ -26,7 +26,10 @@ class Auth implements IMiddleware
}
try {
User::getByToken($token);
$user = User::getByToken($token);
// Keep fresh
$user->keepFresh();
} catch (Exception $err) {
// No user with this token exists
Response::response()

View File

@ -20,7 +20,10 @@ class OptAuth implements IMiddleware
}
try {
User::getByToken($token);
$user = User::getByToken($token);
// Keep fresh
$user->keepFresh();
} catch (Exception $err) {
// No user with this token exists
Response::response()

View File

@ -214,7 +214,7 @@ class User implements JsonSerializable
mail(
$email,
"Account activation GuestBookDB",
"Hello $username. To activate your account, visit https://khofmann.userpage.fu-berlin.de/phpCourse/exam/confirm?c=$guid"
"Hello $username. To activate your account, visit https://khofmann.userpage.fu-berlin.de/phpCourse/exam/confirm?code=$guid"
);
return $user;
@ -239,6 +239,7 @@ class User implements JsonSerializable
WHERE id = :UID"
);
$stmt->bindValue(":UID", $user->getID());
$stmt->execute();
return User::getByID($user->getID());
}
@ -542,6 +543,24 @@ class User implements JsonSerializable
return ["pages" => intdiv($count, $limit + 1) + 1, "data" => $list];
}
public function keepFresh()
{
try {
$db = Database::getInstance();
$stmt = $db->prepare(
"UPDATE
egb_benutzer
SET
tokenExpiry = DATE_ADD(NOW(), INTERVAL " . Config::getTokenExpiry() . "),
refreshExpiry = DATE_ADD(NOW(), INTERVAL " . Config::getRefreshTokenExpiry() . ")
WHERE id = :ID"
);
$stmt->bindValue(":ID", $this->getID());
$stmt->execute();
} catch (Exception $err) {
}
}
/*
* Getters
*/