Files
2026-07-28 10:12:57 +00:00

91 lines
3.5 KiB
PHP

<?php
require __DIR__ . '/includes/auth.php';
require __DIR__ . '/includes/functions.php';
$pdo = require __DIR__ . '/includes/db.php';
$userCount = (int)$pdo->query('SELECT COUNT(*) FROM users')->fetchColumn();
// Sobald ein Mitglied existiert, ist die Ersteinrichtung für immer gesperrt.
if ($userCount > 0) {
header('Location: login.php');
exit;
}
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
csrf_check();
$name = trim($_POST['name'] ?? '');
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
$password2 = $_POST['password2'] ?? '';
if ($name === '' || $username === '' || $password === '') {
$error = 'Bitte alle Felder ausfüllen.';
} elseif (strlen($password) < 8) {
$error = 'Das Passwort sollte mindestens 8 Zeichen haben.';
} elseif ($password !== $password2) {
$error = 'Die beiden Passwörter stimmen nicht überein.';
} else {
$stmt = $pdo->prepare('INSERT INTO users (username, password_hash, name) VALUES (?, ?, ?)');
$stmt->execute([$username, password_hash($password, PASSWORD_DEFAULT), $name]);
session_regenerate_id(true);
$_SESSION['user_id'] = $pdo->lastInsertId();
$_SESSION['user_name'] = $name;
header('Location: admin.php?willkommen=1');
exit;
}
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ersteinrichtung · 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">Einmalige Ersteinrichtung</p>
<h1>Erstes Mitgliedskonto anlegen</h1>
<p>Diese Seite ist nur sichtbar, solange noch kein Mitgliedskonto existiert. Danach ist sie automatisch gesperrt. Lege hier den ersten Zugang an — weitere Mitglieder können später im Mitgliederbereich selbst hinzugefügt werden.</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="name">Name</label>
<input type="text" id="name" name="name" required autofocus placeholder="z. B. Andreas Kopp">
</div>
<div class="field">
<label for="username">Benutzername</label>
<input type="text" id="username" name="username" required placeholder="z. B. andreas">
</div>
<div class="field">
<label for="password">Passwort</label>
<input type="password" id="password" name="password" required>
</div>
<div class="field">
<label for="password2">Passwort wiederholen</label>
<input type="password" id="password2" name="password2" required>
</div>
<button type="submit" class="btn">Konto anlegen &amp; einrichten</button>
</form>
</div>
</section>
<?php include __DIR__ . '/includes/footer.php'; ?>
</body>
</html>