From cf10316ae68a032905f81d4faf8fb5f7b260c12b Mon Sep 17 00:00:00 2001 From: torsten Date: Sun, 4 Oct 2026 11:27:46 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Implementiere=20Admin-Men=C3=BC=20und?= =?UTF-8?q?=20Zugriffsbeschr=C3=A4nkung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: aider (gemini/gemini-2.5-pro) --- public/index.php | 4 ++++ src/Core/Auth.php | 20 +++++++++++++++++++ src/Views/admin.php | 36 +++++++++++++++++++++++++++++++++++ src/Views/partials/header.php | 4 +++- 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/Views/admin.php diff --git a/public/index.php b/public/index.php index 8be50e4..e5d078d 100644 --- a/public/index.php +++ b/public/index.php @@ -49,6 +49,10 @@ if ($page === 'login') { Auth::logout(); header('Location: /index.php?page=login'); exit; +} elseif ($page === 'admin') { + Auth::requireLogin(); + Auth::requireAdmin(); + require __DIR__ . '/../src/Views/admin.php'; } elseif ($page === 'round' && isset($_GET['id'])) { Auth::requireLogin(); try { diff --git a/src/Core/Auth.php b/src/Core/Auth.php index 46273a9..7738a3d 100644 --- a/src/Core/Auth.php +++ b/src/Core/Auth.php @@ -80,6 +80,16 @@ class Auth { return self::$user; } + /** + * Prüft, ob der angemeldete Benutzer ein Admin ist. + * + * @return bool + */ + public static function isAdmin() { + $user = self::user(); + return $user && $user['admin'] == 1; + } + /** * Leitet zur Login-Seite weiter, wenn der Benutzer nicht angemeldet ist. */ @@ -89,4 +99,14 @@ class Auth { exit; } } + + /** + * Leitet zur Startseite, wenn der Benutzer kein Admin ist. + */ + public static function requireAdmin() { + if (!self::isAdmin()) { + header('Location: /index.php'); + exit; + } + } } diff --git a/src/Views/admin.php b/src/Views/admin.php new file mode 100644 index 0000000..0b51a11 --- /dev/null +++ b/src/Views/admin.php @@ -0,0 +1,36 @@ + + +

Administration

+ + + + + + diff --git a/src/Views/partials/header.php b/src/Views/partials/header.php index b7500d4..60afdde 100644 --- a/src/Views/partials/header.php +++ b/src/Views/partials/header.php @@ -15,7 +15,9 @@