Authentication: replace checkExists with Member::fromId

This commit is contained in:
Aaron van Geffen 2024-11-05 16:46:53 +01:00
parent 8eaeb6c332
commit 084658820e

View File

@ -12,22 +12,6 @@
*/
class Authentication
{
/**
* Checks whether a user still exists in the database.
*/
public static function checkExists($id_user)
{
$res = Registry::get('db')->queryValue('
SELECT id_user
FROM users
WHERE id_user = {int:id}',
[
'id' => $id_user,
]);
return $res !== null;
}
/**
* Checks a password for a given username against the database.
*/
@ -78,8 +62,18 @@ class Authentication
*/
public static function isLoggedIn()
{
// A user is logged in if a user id exists in the session and this id is (still) in the database.
return isset($_SESSION['user_id']) && self::checkExists($_SESSION['user_id']);
if (!isset($_SESSION['user_id']))
return false;
try
{
$exists = Member::fromId($_SESSION['user_id']);
return true;
}
catch (NotFoundException $e)
{
return false;
}
}
/**