From 084658820ec4aa235303cbe643a894ef4c1cab5c Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 5 Nov 2024 16:46:53 +0100 Subject: [PATCH] Authentication: replace checkExists with Member::fromId --- models/Authentication.php | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/models/Authentication.php b/models/Authentication.php index afcc55d..8793282 100644 --- a/models/Authentication.php +++ b/models/Authentication.php @@ -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; + } } /**