login.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. declare(strict_types=1);
  3. use App\App\Bootstrap;
  4. use App\Admin\Auth;
  5. use App\Security\Csrf;
  6. require dirname(__DIR__) . '/src/autoload.php';
  7. Bootstrap::init();
  8. $app = Bootstrap::config('app');
  9. $auth = new Auth();
  10. if (isset($_GET['logout']) && $_GET['logout'] === '1') {
  11. $auth->logout();
  12. header('Location: ' . Bootstrap::url('admin/login.php'));
  13. exit;
  14. }
  15. if ($auth->isLoggedIn()) {
  16. header('Location: ' . Bootstrap::url('admin/index.php'));
  17. exit;
  18. }
  19. $error = '';
  20. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  21. if (!Csrf::validate((string) ($_POST['csrf'] ?? ''))) {
  22. $error = 'Ungültiges CSRF-Token.';
  23. } else {
  24. $password = (string) ($_POST['password'] ?? '');
  25. if ($auth->login($password)) {
  26. header('Location: ' . Bootstrap::url('admin/index.php'));
  27. exit;
  28. }
  29. $error = 'Login fehlgeschlagen.';
  30. }
  31. }
  32. $csrf = Csrf::token();
  33. ?><!doctype html>
  34. <html lang="de">
  35. <head>
  36. <meta charset="utf-8">
  37. <meta name="viewport" content="width=device-width, initial-scale=1">
  38. <title>Admin Login</title>
  39. <link rel="stylesheet" href="<?= htmlspecialchars(Bootstrap::url('assets/css/tokens.css')) ?>">
  40. <link rel="stylesheet" href="<?= htmlspecialchars(Bootstrap::url('assets/css/base.css')) ?>">
  41. </head>
  42. <body class="admin-page">
  43. <header class="site-header">
  44. <div class="container header-inner">
  45. <a class="brand" href="<?= htmlspecialchars(Bootstrap::url('admin/login.php')) ?>">
  46. <img class="brand-logo" src="<?= htmlspecialchars(Bootstrap::url('assets/images/feuerwehr-Logo-invers.webp')) ?>" alt="Feuerwehr Logo">
  47. <div class="brand-title"><?= htmlspecialchars((string) ($app['project_name'] ?? 'Admin')) ?></div>
  48. </a>
  49. </div>
  50. </header>
  51. <main class="container">
  52. <section class="card auth-container">
  53. <h1>Admin Login</h1>
  54. <?php if ($error !== ''): ?>
  55. <p class="alert alert-error"><?= htmlspecialchars($error) ?></p>
  56. <?php endif; ?>
  57. <form method="post">
  58. <input type="hidden" name="csrf" value="<?= htmlspecialchars($csrf) ?>">
  59. <div class="field">
  60. <label for="password">Passwort</label>
  61. <input id="password" name="password" type="password" required>
  62. </div>
  63. <button type="submit" class="btn">Anmelden</button>
  64. </form>
  65. </section>
  66. </main>
  67. </body>
  68. </html>