added moderation portal with admin authentification and seperate styling
This commit is contained in:
41
public/api/auth.php
Normal file
41
public/api/auth.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// =====================================================================
|
||||
// Admin Authentication Helper
|
||||
// Provides simple Password-based Session Authentication for the
|
||||
// Moderation Page. Uses ADMIN_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;
|
||||
}
|
||||
|
||||
// Authenticates with Password, returns true on Success
|
||||
function admin_login($password) {
|
||||
$correct = get_admin_password();
|
||||
if ($correct && $password === $correct) {
|
||||
$_SESSION['is_admin'] = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Logs out Admin Session
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -67,9 +67,16 @@ function handle_read($input) {
|
||||
// Builds SQL Query with Placeholders for prepared Statement
|
||||
$sql = "SELECT *, ST_AsGeoJSON(geom) AS geojson
|
||||
FROM contributions
|
||||
WHERE municipality_id = :mid AND status = 'approved'";
|
||||
WHERE municipality_id = :mid";
|
||||
$params = [':mid' => $municipality_id];
|
||||
|
||||
// Optional: Filters by Status (Default: only approved)
|
||||
$status = $input['status'] ?? 'approved';
|
||||
if ($status !== 'all') {
|
||||
$sql .= " AND status = :status";
|
||||
$params[':status'] = $status;
|
||||
}
|
||||
|
||||
// Optional: Filters by Category
|
||||
if (!empty($input['category'])) {
|
||||
$sql .= " AND category = :cat";
|
||||
|
||||
Reference in New Issue
Block a user