login.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. require_once __DIR__ . '/../config.php';
  3. require_once __DIR__ . '/../includes/functions.php';
  4. // Handle logout
  5. if (isset($_GET['logout'])) {
  6. $_SESSION['admin_logged_in'] = false;
  7. unset($_SESSION['admin_username']);
  8. session_destroy();
  9. header('Location: login.php');
  10. exit;
  11. }
  12. $error = '';
  13. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  14. $username = normalizeAdminUsername($_POST['username'] ?? '');
  15. $password = $_POST['password'] ?? '';
  16. $users = getAdminUsers();
  17. if (isset($users[$username]) && password_verify($password, $users[$username])) {
  18. $_SESSION['admin_logged_in'] = true;
  19. $_SESSION['admin_username'] = $username;
  20. header('Location: index.php');
  21. exit;
  22. } else {
  23. $error = 'Benutzername oder Passwort falsch.';
  24. }
  25. }
  26. // Redirect if already logged in
  27. if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in']) {
  28. header('Location: index.php');
  29. exit;
  30. }
  31. ?>
  32. <!DOCTYPE html>
  33. <html lang="de">
  34. <head>
  35. <meta charset="UTF-8">
  36. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  37. <title>Administration - <?php echo escape(SITE_FULL_NAME); ?></title>
  38. <link rel="stylesheet" href="<?php echo escape(SITE_URL); ?>/assets/css/style.css">
  39. </head>
  40. <body class="admin-page">
  41. <header class="site-header">
  42. <div class="container header-inner">
  43. <a class="brand" href="<?php echo escape(SITE_URL); ?>/index.php">
  44. <img class="brand-logo" src="<?php echo escape(SITE_URL); ?>/assets/branding/stadt-freising-logo.png" alt="Wappen der Stadt Freising">
  45. <div class="brand-text">
  46. <span class="brand-title"><?php echo escape(SITE_NAME); ?></span>
  47. <span class="brand-subtitle"><?php echo escape(SITE_SERVICE_HEADER); ?></span>
  48. </div>
  49. </a>
  50. <a href="<?php echo escape(SITE_URL); ?>/index.php" class="btn btn-secondary">Zurück zu <?php echo escape(SITE_SERVICE_NAME); ?></a>
  51. </div>
  52. </header>
  53. <main>
  54. <div class="container container-narrow page-top-gap">
  55. <h2>Administration</h2>
  56. <?php if ($error): ?>
  57. <div class="alert alert-error">
  58. <?php echo htmlspecialchars($error); ?>
  59. </div>
  60. <?php endif; ?>
  61. <form method="POST" class="panel panel-lg">
  62. <div class="form-group">
  63. <label for="username">Benutzername:</label>
  64. <input type="text" id="username" name="username" required autofocus>
  65. </div>
  66. <div class="form-group">
  67. <label for="password">Passwort:</label>
  68. <input type="password" id="password" name="password" required>
  69. </div>
  70. <button type="submit" class="btn btn-block">Anmelden</button>
  71. </form>
  72. <div class="text-center mt-2">
  73. <a href="<?php echo escape(SITE_URL); ?>/index.php">Zurück zu <?php echo escape(SITE_SERVICE_NAME); ?></a>
  74. </div>
  75. </div>
  76. </main>
  77. </body>
  78. </html>