83 lines
2.6 KiB
PHP
83 lines
2.6 KiB
PHP
<?php
|
|
require __DIR__ . '/includes/auth.php';
|
|
require __DIR__ . '/includes/functions.php';
|
|
$pdo = require __DIR__ . '/includes/db.php';
|
|
|
|
// Wenn noch gar kein Mitglied existiert, zur Ersteinrichtung schicken
|
|
$userCount = (int)$pdo->query('SELECT COUNT(*) FROM users')->fetchColumn();
|
|
if ($userCount === 0) {
|
|
header('Location: setup.php');
|
|
exit;
|
|
}
|
|
|
|
if (is_logged_in()) {
|
|
header('Location: admin.php');
|
|
exit;
|
|
}
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
csrf_check();
|
|
$username = trim($_POST['username'] ?? '');
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = ?');
|
|
$stmt->execute([$username]);
|
|
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($user && password_verify($password, $user['password_hash'])) {
|
|
session_regenerate_id(true);
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['user_name'] = $user['name'];
|
|
header('Location: admin.php');
|
|
exit;
|
|
} else {
|
|
$error = 'Benutzername oder Passwort ist falsch.';
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Mitglieder-Login · Geburtsverein Ernsthausen</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700;9..144,800&family=Libre+Franklin:wght@400;500;600;700&family=Space+Mono:wght@400;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="style.css">
|
|
</head>
|
|
<body>
|
|
<?php include __DIR__ . '/includes/nav.php'; ?>
|
|
|
|
<div class="pagehead">
|
|
<div class="pagehead-inner">
|
|
<p class="kicker on-dark">Mitgliederbereich</p>
|
|
<h1>Anmelden</h1>
|
|
<p>Mit deinem persönlichen Zugang kannst du Termine und Neuigkeiten für die Vereinsseite eintragen.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<section>
|
|
<div class="form-card">
|
|
<?php if ($error): ?><div class="alert error"><?= e($error) ?></div><?php endif; ?>
|
|
<form method="post" novalidate>
|
|
<input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>">
|
|
<div class="field">
|
|
<label for="username">Benutzername</label>
|
|
<input type="text" id="username" name="username" required autofocus>
|
|
</div>
|
|
<div class="field">
|
|
<label for="password">Passwort</label>
|
|
<input type="password" id="password" name="password" required>
|
|
</div>
|
|
<button type="submit" class="btn">Anmelden</button>
|
|
</form>
|
|
</div>
|
|
</section>
|
|
|
|
<?php include __DIR__ . '/includes/footer.php'; ?>
|
|
</body>
|
|
</html>
|