login.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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>Admin Login - <?php echo SITE_NAME; ?></title>
  38. <link rel="stylesheet" href="<?php echo SITE_URL; ?>/assets/css/style.css">
  39. </head>
  40. <body>
  41. <header>
  42. <div class="container">
  43. <h1><?php echo SITE_NAME; ?> - Admin</h1>
  44. </div>
  45. </header>
  46. <main>
  47. <div class="container" style="max-width: 400px; margin-top: 4rem;">
  48. <h2>Admin Login</h2>
  49. <?php if ($error): ?>
  50. <div class="alert alert-error">
  51. <?php echo htmlspecialchars($error); ?>
  52. </div>
  53. <?php endif; ?>
  54. <form method="POST" class="panel" style="padding: 2rem;">
  55. <div class="form-group">
  56. <label for="username">Benutzername:</label>
  57. <input type="text" id="username" name="username" required autofocus>
  58. </div>
  59. <div class="form-group">
  60. <label for="password">Passwort:</label>
  61. <input type="password" id="password" name="password" required>
  62. </div>
  63. <button type="submit" class="btn" style="width: 100%;">Anmelden</button>
  64. </form>
  65. <div style="text-align: center; margin-top: 1rem;">
  66. <a href="<?php echo SITE_URL; ?>/index.php">Zurück zum Shop</a>
  67. </div>
  68. </div>
  69. </main>
  70. </body>
  71. </html>