This commit is contained in:
2025-12-26 01:12:16 +01:00
parent c8f2dc384b
commit d9ee8b2129
5 changed files with 181 additions and 9 deletions

View File

@@ -1,26 +1,67 @@
<?php
$app = app();
$flash = $app->flash()->get();
$isLoggedIn = isset($_SESSION['user_id']);
$error = '';
$displayName = '';
$email = '';
if ($isLoggedIn) {
redirect('/dashboard');
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$displayName = trim((string)($_POST['display_name'] ?? ''));
$email = trim((string)($_POST['email'] ?? ''));
$password = (string)($_POST['password'] ?? '');
$password2 = (string)($_POST['password_confirm'] ?? '');
if ($password !== $password2) {
$error = 'Passwörter stimmen nicht überein.';
} elseif (strlen($password) < 8) {
$error = 'Passwort muss mindestens 8 Zeichen haben.';
} else {
try {
$auth = new \App\Auth($app);
$userId = $auth->register($displayName, $email, $password);
$_SESSION['user_id'] = $userId;
$app->flash()->set('success', 'Willkommen! Dein Account wurde erstellt.');
redirect('/dashboard');
} catch (\Throwable $e) {
$error = $e->getMessage();
}
}
}
?>
<main class="auth-wrap">
<div class="container auth-grid">
<section class="card auth-card">
<div class="badge">Registrierung</div>
<h1 class="mt-1" style="margin: 12px 0;">Jetzt Account anlegen</h1>
<p class="muted">Registriere dich mit wenigen Angaben. Alles Weitere pflegst du später im Mitgliederbereich.</p>
<form class="stack gap-12" style="margin-top: 14px;">
<?php if ($flash): ?>
<div class="toast-bar" style="margin-top: 10px;"><?= htmlspecialchars($flash['message'], ENT_QUOTES) ?></div>
<?php endif; ?>
<?php if ($error): ?>
<div class="toast-bar" style="margin-top: 10px; border-color:#f87171; color:#991b1b;">Fehler: <?= htmlspecialchars($error, ENT_QUOTES) ?></div>
<?php endif; ?>
<form class="stack gap-12" style="margin-top: 14px;" method="post" action="/register">
<div class="stack gap-6">
<label class="label" for="regName">Anzeigename</label>
<input id="regName" name="display_name" class="input" required placeholder="z. B. Papa Alex">
<input id="regName" name="display_name" class="input" required placeholder="z. B. Papa Alex" value="<?= htmlspecialchars($displayName ?? '', ENT_QUOTES) ?>">
</div>
<div class="stack gap-6">
<label class="label" for="regEmail">E-Mail</label>
<input id="regEmail" name="email" class="input" type="email" required placeholder="du@example.com">
<input id="regEmail" name="email" class="input" type="email" required placeholder="du@example.com" value="<?= htmlspecialchars($email ?? '', ENT_QUOTES) ?>">
</div>
<div class="form-grid">
<div class="stack gap-6">
<label class="label" for="regPassword">Passwort</label>
<input id="regPassword" name="password" class="input" type="password" required placeholder="********">
<input id="regPassword" name="password" class="input" type="password" required placeholder="********" autocomplete="new-password">
</div>
<div class="stack gap-6">
<label class="label" for="regPassword2">Passwort bestätigen</label>
<input id="regPassword2" name="password_confirm" class="input" type="password" required placeholder="********">
<input id="regPassword2" name="password_confirm" class="input" type="password" required placeholder="********" autocomplete="new-password">
</div>
</div>
<button class="btn block" type="submit">Account erstellen</button>