This commit is contained in:
2025-11-19 00:49:53 +01:00
parent 553fefbeaa
commit 0834e1f733
12 changed files with 725 additions and 524 deletions

View File

@@ -1,177 +1,201 @@
<?php
// public/account.php
declare(strict_types=1);
require_once __DIR__ . '/../src/auth.php';
require __DIR__ . '/../src/auth.php';
$lang = auth_get_lang();
auth_require_login();
$user = auth_current_user();
$csrfToken = auth_csrf_token();
$lang = auth_get_lang();
$user = auth_current_user();
$errors = [];
$flashSuccess = '';
$flashError = '';
$profileErrors = [];
$profileSuccess = false;
// --- Profil-Update (Name + Sprache) ---
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'update_profile') {
if (!auth_verify_csrf($_POST['csrf_token'] ?? null)) {
$profileErrors['csrf'] = 'Deine Sitzung ist abgelaufen. Bitte Seite neu laden.';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!auth_verify_csrf($_POST['_csrf'] ?? null)) {
$flashError = 'Sicherheitsfehler. Bitte Formular erneut absenden.';
} else {
$fullName = $_POST['full_name'] ?? '';
$preferredLang = $_POST['preferred_lang'] ?? $lang;
$fullName = $_POST['full_name'] ?? ($user['full_name'] ?? '');
$preferredLang = $_POST['preferred_lang'] ?? ($user['preferred_lang'] ?? $lang);
$result = auth_update_profile((int)$user['id'], $fullName, $preferredLang);
if ($result['success']) {
$profileSuccess = true;
if ($result['success'] ?? false) {
$flashSuccess = 'Profil wurde aktualisiert.';
$user = auth_current_user(); // neu laden
$lang = auth_get_lang(); // kann sich geändert haben
} else {
$profileErrors = $result['errors'];
$errors = $result['errors'] ?? [];
}
}
}
// --- Avatar-Initialen ---
$initials = auth_user_initials($user);
$csrfToken = auth_csrf_token();
$initials = auth_user_initials($user);
$avatarUrl = auth_user_avatar_url($user);
?>
<!DOCTYPE html>
<html lang="<?php echo htmlspecialchars($lang, ENT_QUOTES); ?>">
<html lang="<?php echo htmlspecialchars($lang, ENT_QUOTES, 'UTF-8'); ?>">
<head>
<meta charset="UTF-8">
<title>Mein Konto USBCheck</title>
<title>Mein Konto usbcheck.it</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Fonts -->
<!-- Fonts: Montserrat + Inter -->
<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 -->
<!-- Main stylesheet -->
<link rel="stylesheet" href="/assets/css/main.css?v=1">
</head>
<body>
<?php
$langVar = $lang;
include __DIR__ . '/partials/header.php';
?>
<?php include __DIR__ . '/partials/header.php'; ?>
<main class="page-main">
<section class="section">
<div class="container">
<h1 class="section-title" data-i18n="account_title">Mein Konto</h1>
<p class="section-lead" data-i18n="account_intro">
Verwalte deine Profildaten und behalte deine USB-Tests im Überblick.
</p>
<main class="account-page">
<div class="container">
<div class="account-grid">
<!-- Profil -->
<section class="account-card">
<h1 class="account-title">Mein Profil</h1>
<p class="account-subtitle">
Passe deinen Namen und deine bevorzugte Sprache an. Der Avatar wird aktuell aus deinen Initialen generiert.
</p>
<div class="account-layout">
<!-- Sidebar: Avatar + Basisinfos -->
<aside class="account-sidebar">
<div class="account-avatar">
<?php if ($avatarUrl): ?>
<img src="<?php echo htmlspecialchars($avatarUrl, ENT_QUOTES); ?>" alt="Avatar">
<?php else: ?>
<div class="avatar-circle">
<span><?php echo htmlspecialchars($initials, ENT_QUOTES); ?></span>
</div>
<?php if ($flashSuccess): ?>
<div class="auth-flash-success">
<?php echo htmlspecialchars($flashSuccess, ENT_QUOTES, 'UTF-8'); ?>
</div>
<?php endif; ?>
<?php if ($flashError): ?>
<div class="auth-flash-error">
<?php echo htmlspecialchars($flashError, ENT_QUOTES, 'UTF-8'); ?>
</div>
<?php endif; ?>
<form method="post" novalidate>
<input type="hidden" name="_csrf" value="<?php echo htmlspecialchars($csrfToken, ENT_QUOTES, 'UTF-8'); ?>">
<div class="form-row">
<label class="form-label" for="email">E-Mail-Adresse</label>
<input
class="form-input"
type="email"
id="email"
name="email"
value="<?php echo htmlspecialchars($user['email'] ?? '', ENT_QUOTES, 'UTF-8'); ?>"
readonly
>
<div class="form-help">
E-Mail-Änderungen bitte später über einen separaten Flow.
</div>
</div>
<div class="form-row">
<label class="form-label" for="username">Benutzername</label>
<input
class="form-input"
type="text"
id="username"
name="username"
value="<?php echo htmlspecialchars($user['username'] ?? '', ENT_QUOTES, 'UTF-8'); ?>"
readonly
>
<div class="form-help">
Benutzername ist aktuell nicht änderbar.
</div>
</div>
<div class="form-row">
<label class="form-label" for="full_name">Vollständiger Name</label>
<input
class="form-input"
type="text"
id="full_name"
name="full_name"
required
value="<?php echo htmlspecialchars($_POST['full_name'] ?? ($user['full_name'] ?? ''), ENT_QUOTES, 'UTF-8'); ?>"
>
<?php if (!empty($errors['full_name'])): ?>
<div class="form-error"><?php echo htmlspecialchars($errors['full_name'], ENT_QUOTES, 'UTF-8'); ?></div>
<?php endif; ?>
</div>
<div class="account-basic-info">
<h2><?php echo htmlspecialchars($user['full_name'] ?? $user['username'], ENT_QUOTES); ?></h2>
<p class="muted">
<?php echo htmlspecialchars($user['email'], ENT_QUOTES); ?>
</p>
<p class="muted">
Username: <?php echo htmlspecialchars($user['username'], ENT_QUOTES); ?>
</p>
<div class="form-row">
<label class="form-label" for="preferred_lang">Bevorzugte Sprache</label>
<select class="form-select" id="preferred_lang" name="preferred_lang">
<?php
$selLang = $_POST['preferred_lang'] ?? ($user['preferred_lang'] ?? $lang);
$opts = [
'de' => 'Deutsch',
'en' => 'English',
'it' => 'Italiano',
'fr' => 'Français',
];
foreach ($opts as $code => $label) {
$selected = ($code === $selLang) ? 'selected' : '';
echo '<option value="' . htmlspecialchars($code, ENT_QUOTES, 'UTF-8') . '" ' . $selected . '>'
. htmlspecialchars($label, ENT_QUOTES, 'UTF-8') . '</option>';
}
?>
</select>
</div>
<div class="account-links">
<a class="btn btn-outline" href="/fakecheck/?lang=<?php echo urlencode($lang); ?>" data-i18n="account_start_test">
USB-Test starten
</a>
<a class="btn btn-ghost" href="/logout.php?lang=<?php echo urlencode($lang); ?>" data-i18n="account_logout">
Abmelden
<div class="form-actions">
<button type="submit" class="btn btn-primary">
Änderungen speichern
</button>
<a href="/logout.php" class="auth-link">
Logout
</a>
</div>
</aside>
</form>
</section>
<!-- Main: Profilformular + Platzhalter für später -->
<section class="account-main">
<div class="card">
<h2 data-i18n="account_profile_heading">Profil</h2>
<!-- Avatar / Meta -->
<section class="account-card">
<h2 class="account-title">Avatar &amp; Konto</h2>
<p class="account-subtitle">
Dein Avatar wird aktuell aus deinen Initialen erzeugt. Später kannst du hier ein eigenes Bild hochladen.
</p>
<?php if (!empty($profileErrors['csrf'])): ?>
<div class="alert alert-error">
<?php echo htmlspecialchars($profileErrors['csrf'], ENT_QUOTES); ?>
</div>
<?php endif; ?>
<?php if ($profileSuccess): ?>
<div class="alert alert-success" data-i18n="account_profile_updated">
Profil wurde aktualisiert.
</div>
<?php endif; ?>
<form method="post" action="/account.php?lang=<?php echo urlencode($lang); ?>">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($csrfToken, ENT_QUOTES); ?>">
<input type="hidden" name="action" value="update_profile">
<div class="form-row">
<label for="full_name" data-i18n="account_full_name_label">Vollständiger Name</label>
<input
type="text"
id="full_name"
name="full_name"
required
value="<?php echo htmlspecialchars($user['full_name'] ?? '', ENT_QUOTES); ?>"
>
<?php if (!empty($profileErrors['full_name'])): ?>
<p class="form-error"><?php echo htmlspecialchars($profileErrors['full_name'], ENT_QUOTES); ?></p>
<?php endif; ?>
</div>
<div class="form-row">
<label for="preferred_lang" data-i18n="account_lang_label">Bevorzugte Sprache</label>
<select id="preferred_lang" name="preferred_lang">
<?php
$pl = $user['preferred_lang'] ?? $lang;
?>
<option value="de" <?php echo $pl === 'de' ? 'selected' : ''; ?>>Deutsch</option>
<option value="en" <?php echo $pl === 'en' ? 'selected' : ''; ?>>English</option>
<option value="it" <?php echo $pl === 'it' ? 'selected' : ''; ?>>Italiano</option>
<option value="fr" <?php echo $pl === 'fr' ? 'selected' : ''; ?>>Français</option>
</select>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary" data-i18n="account_profile_save">
Änderungen speichern
</button>
</div>
</form>
<div class="account-avatar-preview">
<?php if ($avatarUrl): ?>
<div class="user-avatar" style="background-image:url('<?php echo htmlspecialchars($avatarUrl, ENT_QUOTES, 'UTF-8'); ?>'); background-size:cover; background-position:center; color:transparent;">
&nbsp;
</div>
<?php else: ?>
<div class="user-avatar">
<?php echo htmlspecialchars($initials, ENT_QUOTES, 'UTF-8'); ?>
</div>
<?php endif; ?>
<div class="account-avatar-note">
<strong>Avatar-Vorschau</strong><br>
Standardmäßig Initialen aus deinem Namen.<br>
Upload-Funktion folgt in einem späteren Schritt.
</div>
</div>
<div class="card card-muted">
<h2 data-i18n="account_usb_heading">Deine USB-Sticks & Testergebnisse</h2>
<p class="muted" data-i18n="account_usb_placeholder">
Hier wirst du später eine Übersicht deiner registrierten USB-Sticks und Testergebnisse sehen.
</p>
</div>
<div class="card card-muted">
<h2 data-i18n="account_avatar_heading">Avatar</h2>
<p class="muted" data-i18n="account_avatar_placeholder">
Standardmäßig verwenden wir deine Initialen. Später kannst du hier ein eigenes Profilbild hochladen.
</p>
</div>
</section>
</div>
<div class="account-meta" style="margin-top:1.5rem;">
<p><strong>Account-ID:</strong> <?php echo (int)$user['id']; ?></p>
<p><strong>Registriert am:</strong>
<?php
if (!empty($user['created_at'])) {
echo htmlspecialchars($user['created_at'], ENT_QUOTES, 'UTF-8');
} else {
echo '';
}
?>
</p>
</div>
</section>
</div>
</section>
</div>
</main>
<?php include __DIR__ . '/partials/footer.php'; ?>
<script src="/assets/js/lang.js?v=1"></script>
</body>
</html>