From 9797caa58e28170320b332f644bd7331e634b1ae Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Thu, 24 Apr 2025 12:37:59 +0300 Subject: [PATCH] Moves session auth logic to the new core/Router class --- public_html/index.php | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/public_html/index.php b/public_html/index.php index 0e7c4bb..51542f6 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -171,31 +171,9 @@ function filter_public_pages($pages) { } $public_pages = filter_public_pages($public_pages); -// Check session and redirect if needed -$currentUser = null; -if ($validSession) { - // Session is OK - $currentUser = Session::getUsername(); -} else if (!in_array($page, $public_pages)) { - // Session expired/invalid, page needs login - if (isset($_SESSION['LAST_ACTIVITY']) && !isset($_SESSION['session_timeout_shown'])) { - // Only show session timeout message if there was an active session - // and we haven't shown it yet - Feedback::flash('LOGIN', 'SESSION_TIMEOUT'); - $_SESSION['session_timeout_shown'] = true; - // Cleanup session but keep flash messages - $flash_messages = $_SESSION['flash_messages'] ?? []; - Session::cleanup($config); - $_SESSION['flash_messages'] = $flash_messages; - } - $loginUrl = $app_root . '?page=login'; - $trimmed = trim($page, '/?'); - if (!in_array($trimmed, INVALID_REDIRECT_PAGES, true)) { - $loginUrl .= '&redirect=' . urlencode($_SERVER['REQUEST_URI']); - } - header('Location: ' . $loginUrl); - exit(); -} +// Dispatch routing and auth +require_once __DIR__ . '/../app/core/Router.php'; +$currentUser = \App\Core\Router::checkAuth($config, $app_root, $public_pages, $page); // connect to db of Jilo Web require '../app/classes/database.php';