From 59c9d80443d0b48a01094f907616dea2e2d76c4d Mon Sep 17 00:00:00 2001 From: Andreas Date: Thu, 10 Oct 2024 23:32:13 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Bug=20fix:=20logout=20not=20alwa?= =?UTF-8?q?ys=20working?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed a bug where logout wasn`t working in all browsers --- src/app/controllers/UserController.php | 11 ++++------- src/auth/login.php | 18 ++++++++++++++++-- src/auth/logout.php | 2 -- src/index.php | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/app/controllers/UserController.php b/src/app/controllers/UserController.php index 5518b7a6..aa271bcc 100644 --- a/src/app/controllers/UserController.php +++ b/src/app/controllers/UserController.php @@ -36,15 +36,12 @@ public function logoutUser($log = true) if ($log) { $this->log($username, "Logged out", auth_logs); } - - setcookie("login_cookie", "", time() - 3600, '/'); - session_unset(); - $_SESSION = []; - $_SESSION = array(); - session_destroy(); - Util::redirect("/auth/login.php"); + Util::redirect("/auth/login.php?action=logout"); } + + + public function getUserArray() { return $this->UserArray(); diff --git a/src/auth/login.php b/src/auth/login.php index 0c74bde2..8fd859c3 100644 --- a/src/auth/login.php +++ b/src/auth/login.php @@ -7,9 +7,23 @@ Session::init(); -if (Session::isLogged()) { - Util::redirect('/'); + +if (Util::securevar($_SERVER['REQUEST_METHOD']) === 'GET') { + if (isset($_GET['action'])) { + $data = Util::securevar($_GET['action']); + + if ($data === 'logout') { + setcookie("login_cookie", "", time() - 3600, '/'); + session_unset(); + $_SESSION = []; + session_destroy(); + Util::redirect('/auth/login.php'); + } + } } + + + if (Util::securevar($_SERVER['REQUEST_METHOD']) === 'POST') { if (isset($_POST)) { $data = Util::securevar($_POST); diff --git a/src/auth/logout.php b/src/auth/logout.php index cd5cdd10..adc1b2ea 100644 --- a/src/auth/logout.php +++ b/src/auth/logout.php @@ -10,5 +10,3 @@ $user = new UserController(); $user->logoutUser(); - -Util::redirect('/auth/login.php'); diff --git a/src/index.php b/src/index.php index 87214927..1bf608fc 100644 --- a/src/index.php +++ b/src/index.php @@ -204,7 +204,7 @@ $loginfails = Session::get("loginfails"); if ($loginfails > 0) : ?>
- Security Warning: failed login attempts + Security Warning: failed login attempts