login.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. session_destroy();
  8. header('Location: login.php');
  9. exit;
  10. }
  11. $error = '';
  12. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  13. $username = sanitize($_POST['username'] ?? '');
  14. $password = $_POST['password'] ?? '';
  15. $users = defined('ADMIN_USERS') ? ADMIN_USERS : [];
  16. if (isset($users[$username]) && password_verify($password, $users[$username])) {
  17. $_SESSION['admin_logged_in'] = true;
  18. header('Location: index.php');
  19. exit;
  20. } else {
  21. $error = 'Benutzername oder Passwort falsch.';
  22. }
  23. }
  24. // Redirect if already logged in
  25. if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in']) {
  26. header('Location: index.php');
  27. exit;
  28. }
  29. ?>
  30. <!DOCTYPE html>
  31. <html lang="de">
  32. <head>
  33. <meta charset="UTF-8">
  34. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  35. <title>Admin Login - <?php echo SITE_NAME; ?></title>
  36. <link rel="stylesheet" href="<?php echo SITE_URL; ?>/assets/css/style.css">
  37. </head>
  38. <body>
  39. <header>
  40. <div class="container">
  41. <h1><?php echo SITE_NAME; ?> - Admin</h1>
  42. </div>
  43. </header>
  44. <main>
  45. <div class="container" style="max-width: 400px; margin-top: 4rem;">
  46. <h2>Admin Login</h2>
  47. <?php if ($error): ?>
  48. <div class="alert alert-error">
  49. <?php echo htmlspecialchars($error); ?>
  50. </div>
  51. <?php endif; ?>
  52. <form method="POST" style="background: white; padding: 2rem; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
  53. <div class="form-group">
  54. <label for="username">Benutzername:</label>
  55. <input type="text" id="username" name="username" required autofocus>
  56. </div>
  57. <div class="form-group">
  58. <label for="password">Passwort:</label>
  59. <input type="password" id="password" name="password" required>
  60. </div>
  61. <button type="submit" class="btn" style="width: 100%;">Anmelden</button>
  62. </form>
  63. <div style="text-align: center; margin-top: 1rem;">
  64. <a href="<?php echo SITE_URL; ?>/index.php" style="color: #6c757d;">Zurück zum Shop</a>
  65. </div>
  66. </div>
  67. </main>
  68. </body>
  69. </html>