simplified admin and mod authentification for new moderation page

This commit is contained in:
2026-04-22 14:34:03 +02:00
parent 9d7eb25d1f
commit 27d41c0847

View File

@@ -2,15 +2,10 @@
// =====================================================================
// Admin Authentication Helper
// Provides simple Password-based Session Authentication for the
// Moderation Page. Uses ADMIN_PASSWORD from .env File.
// Moderation Page. Reads Password from .env File.
// ToDo: Replace with full User Authentication in Phase 3-3.
// =====================================================================
// Reads Admin Password from Environment
function get_admin_password() {
return getenv('ADMIN_PASSWORD');
}
// Checks if current Session is authenticated as Admin
function is_admin() {
return isset($_SESSION['is_admin']) && $_SESSION['is_admin'] === true;
@@ -18,7 +13,7 @@ function is_admin() {
// Authenticates with Password, returns true on Success
function admin_login($password) {
$correct = get_admin_password();
$correct = getenv('ADMIN_PASSWORD');
if ($correct && $password === $correct) {
$_SESSION['is_admin'] = true;
return true;
@@ -30,12 +25,4 @@ function admin_login($password) {
function admin_logout() {
$_SESSION['is_admin'] = false;
session_destroy();
}
// Redirects to Login if not authenticated
function require_admin() {
if (!is_admin()) {
header('Location: admin.php?page=login');
exit;
}
}