This commit is contained in:
2025-11-18 03:43:21 +01:00
parent beb7d9c868
commit 9b1f1f0710
16 changed files with 2369 additions and 576 deletions

198
public/register.php Normal file
View File

@@ -0,0 +1,198 @@
<?php
// public/register.php
require_once __DIR__ . '/../src/auth.php';
$lang = auth_get_lang();
$csrfToken = auth_csrf_token();
$currentUser = auth_current_user();
if ($currentUser) {
// Bereits eingeloggt -> Accountseite
header('Location: /account.php?lang=' . urlencode($lang));
exit;
}
$errors = [];
$values = [
'email' => '',
'username' => '',
'full_name' => '',
'preferred_lang' => $lang,
];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!auth_verify_csrf($_POST['csrf_token'] ?? null)) {
$errors['csrf'] = 'Deine Sitzung ist abgelaufen. Bitte Seite neu laden.';
} else {
$email = $_POST['email'] ?? '';
$username = $_POST['username'] ?? '';
$fullName = $_POST['full_name'] ?? '';
$password = $_POST['password'] ?? '';
$passwordConfirm= $_POST['password_confirm'] ?? '';
$preferredLang = $_POST['preferred_lang'] ?? $lang;
$values = [
'email' => $email,
'username' => $username,
'full_name' => $fullName,
'preferred_lang' => $preferredLang,
];
$result = auth_register_user(
$email,
$username,
$fullName,
$password,
$passwordConfirm,
$preferredLang
);
if ($result['success']) {
header('Location: /account.php?lang=' . urlencode($preferredLang));
exit;
} else {
$errors = array_merge($errors, $result['errors']);
}
}
}
?>
<!DOCTYPE html>
<html lang="<?php echo htmlspecialchars($lang, ENT_QUOTES); ?>">
<head>
<meta charset="UTF-8">
<title>Registrierung USBCheck</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Fonts -->
<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=Inter:wght@400;500&family=Montserrat:wght@600;700&display=swap" rel="stylesheet">
<!-- Main CSS -->
<link rel="stylesheet" href="/assets/css/main.css?v=1">
</head>
<body>
<?php
// Header-Partial, erwartet ggf. $lang
$langVar = $lang;
include __DIR__ . '/partials/header.php';
?>
<main class="page-main">
<section class="section">
<div class="container narrow">
<h1 class="section-title" data-i18n="register_title">Konto erstellen</h1>
<p class="section-lead" data-i18n="register_intro">
Erstelle ein kostenloses Konto, um deine USB-Tests zu verwalten.
</p>
<?php if (!empty($errors['csrf'])): ?>
<div class="alert alert-error">
<?php echo htmlspecialchars($errors['csrf'], ENT_QUOTES); ?>
</div>
<?php endif; ?>
<form class="form-card" method="post" action="/register.php?lang=<?php echo urlencode($lang); ?>">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrfToken, ENT_QUOTES); ?>">
<div class="form-row">
<label for="email" data-i18n="register_email_label">E-Mail-Adresse</label>
<input
type="email"
id="email"
name="email"
required
value="<?php echo htmlspecialchars($values['email'], ENT_QUOTES); ?>"
>
<?php if (!empty($errors['email'])): ?>
<p class="form-error"><?php echo htmlspecialchars($errors['email'], ENT_QUOTES); ?></p>
<?php endif; ?>
</div>
<div class="form-row">
<label for="username" data-i18n="register_username_label">Username</label>
<input
type="text"
id="username"
name="username"
required
value="<?php echo htmlspecialchars($values['username'], ENT_QUOTES); ?>"
>
<?php if (!empty($errors['username'])): ?>
<p class="form-error"><?php echo htmlspecialchars($errors['username'], ENT_QUOTES); ?></p>
<?php endif; ?>
</div>
<div class="form-row">
<label for="full_name" data-i18n="register_full_name_label">Vollständiger Name</label>
<input
type="text"
id="full_name"
name="full_name"
required
value="<?php echo htmlspecialchars($values['full_name'], ENT_QUOTES); ?>"
>
<?php if (!empty($errors['full_name'])): ?>
<p class="form-error"><?php echo htmlspecialchars($errors['full_name'], ENT_QUOTES); ?></p>
<?php endif; ?>
</div>
<div class="form-row form-row-inline">
<div>
<label for="password" data-i18n="register_password_label">Passwort</label>
<input
type="password"
id="password"
name="password"
required
minlength="10"
>
<?php if (!empty($errors['password'])): ?>
<p class="form-error"><?php echo htmlspecialchars($errors['password'], ENT_QUOTES); ?></p>
<?php endif; ?>
</div>
<div>
<label for="password_confirm" data-i18n="register_password_confirm_label">Passwort wiederholen</label>
<input
type="password"
id="password_confirm"
name="password_confirm"
required
minlength="10"
>
<?php if (!empty($errors['password_confirm'])): ?>
<p class="form-error"><?php echo htmlspecialchars($errors['password_confirm'], ENT_QUOTES); ?></p>
<?php endif; ?>
</div>
</div>
<div class="form-row">
<label for="preferred_lang" data-i18n="register_lang_label">Bevorzugte Sprache</label>
<select id="preferred_lang" name="preferred_lang">
<option value="de" <?php echo $values['preferred_lang'] === 'de' ? 'selected' : ''; ?>>Deutsch</option>
<option value="en" <?php echo $values['preferred_lang'] === 'en' ? 'selected' : ''; ?>>English</option>
<option value="it" <?php echo $values['preferred_lang'] === 'it' ? 'selected' : ''; ?>>Italiano</option>
<option value="fr" <?php echo $values['preferred_lang'] === 'fr' ? 'selected' : ''; ?>>Français</option>
</select>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary" data-i18n="register_submit">
Konto erstellen
</button>
<p class="form-hint">
<span data-i18n="register_existing_hint">Du hast bereits ein Konto?</span>
<a href="/login.php?lang=<?php echo urlencode($lang); ?>" data-i18n="register_existing_link">
Zum Login
</a>
</p>
</div>
</form>
</div>
</section>
</main>
<script src="/assets/js/lang.js?v=1"></script>
</body>
</html>