login change

This commit is contained in:
2025-11-22 01:44:03 +01:00
parent a5ce6a079a
commit b3a3d25502
9 changed files with 474 additions and 35 deletions

View File

@@ -1,6 +1,19 @@
<?php
// Fallback falls $authView nicht gesetzt ist
$authView = $authView ?? 'login';
// Optional: View über GET-Parameter überschreiben (?view=login|register)
if (isset($_GET['view']) && in_array($_GET['view'], ['login', 'register'], true)) {
$authView = $_GET['view'];
}
// Flash-Meldung holen (falls flash_get() existiert)
$flash = function_exists('flash_get') ? flash_get() : null;
// Wenn eine Flash-Message mit Kontext kommt, Tabs entsprechend umschalten
if ($flash && !empty($flash['context']) && in_array($flash['context'], ['login', 'register'], true)) {
$authView = $flash['context'];
}
?>
<section id="auth" class="border-t border-brand-border/70 bg-brand-primarySoft/20">
<div class="mx-auto max-w-xl px-4 sm:px-6 lg:px-8 py-16 sm:py-20">
@@ -16,6 +29,20 @@ $authView = $authView ?? 'login';
</p>
</div>
<?php if ($flash): ?>
<div class="mb-6 rounded-xl px-4 py-3 text-sm border
<?php if ($flash['type'] === 'error'): ?>
border-red-500/60 bg-red-500/10 text-red-300
<?php elseif ($flash['type'] === 'success'): ?>
border-emerald-500/60 bg-emerald-500/10 text-emerald-300
<?php else: ?>
border-brand-border bg-brand-bg/60 text-brand-muted
<?php endif; ?>
">
<?= htmlspecialchars($flash['message']) ?>
</div>
<?php endif; ?>
<!-- Tabs -->
<div class="mb-6 rounded-full border border-brand-border bg-brand-surface/80 p-1 flex text-xs font-semibold uppercase tracking-[0.18em] text-brand-muted">
<button
@@ -47,8 +74,10 @@ $authView = $authView ?? 'login';
Melde dich mit deiner E-Mail-Adresse und deinem Passwort an.
</p>
<form method="post" action="/login/?lang=<?= htmlspecialchars($lang) ?>" class="space-y-4" autocomplete="on">
<input type="hidden" name="action" value="login">
<form method="post" action="/auth/login" class="space-y-4" autocomplete="on">
<input type="hidden" name="lang" value="<?= htmlspecialchars($lang ?? 'de') ?>">
<input type="hidden" name="redirect" value="<?= htmlspecialchars($_GET['redirect'] ?? '/') ?>">
<input type="hidden" name="authView" value="login">
<div class="space-y-1">
<label for="login_email" class="block text-xs font-semibold tracking-wide uppercase text-brand-muted" data-i18n="auth_login_email_label">
@@ -108,8 +137,10 @@ $authView = $authView ?? 'login';
Erstelle einen kostenlosen Account, um Tests zu speichern, Berichte zu exportieren und den Pro-Modus später freizuschalten.
</p>
<form method="post" action="/login/?lang=<?= htmlspecialchars($lang) ?>" class="space-y-4" autocomplete="on">
<input type="hidden" name="action" value="register">
<form method="post" action="/auth/register" class="space-y-4" autocomplete="on">
<input type="hidden" name="lang" value="<?= htmlspecialchars($lang ?? 'de') ?>">
<input type="hidden" name="redirect" value="<?= htmlspecialchars($_GET['redirect'] ?? '/') ?>">
<input type="hidden" name="authView" value="register">
<div class="space-y-1">
<label for="reg_name" class="block text-xs font-semibold tracking-wide uppercase text-brand-muted" data-i18n="auth_register_name_label">

View File

@@ -10,6 +10,40 @@ $baseUrl = $scheme . '://' . $host;
if (!isset($navAnchors) || !is_array($navAnchors)) {
$navAnchors = [];
}
// Session sollte in config/fileload.php bereits gestartet sein.
// Falls nicht, hier Fallback:
if (session_status() !== PHP_SESSION_ACTIVE) {
@session_start();
}
// aktuellen User aus der Session holen (wenn vorhanden)
$currentUser = $_SESSION['user'] ?? null;
$isLoggedIn = is_array($currentUser) && !empty($currentUser['id']);
// Initialen für Avatar bestimmen
$userInitials = null;
if ($isLoggedIn) {
if (!empty($currentUser['initials'])) {
$userInitials = $currentUser['initials'];
} else {
$firstName = $currentUser['first_name'] ?? '';
$lastName = $currentUser['last_name'] ?? '';
$username = $currentUser['username'] ?? ($currentUser['email'] ?? 'U');
$initials = '';
if ($firstName !== '') {
$initials .= mb_substr($firstName, 0, 1);
}
if ($lastName !== '') {
$initials .= mb_substr($lastName, 0, 1);
}
if ($initials === '') {
$initials = mb_substr($username, 0, 2);
}
$userInitials = mb_strtoupper($initials);
}
}
?>
<header class="sticky top-0 z-40 border-b border-brand-border/70 backdrop-blur bg-brand-bg/85">
<div class="mx-auto max-w-6xl px-4 sm:px-6 lg:px-8 flex items-center justify-between h-16">
@@ -44,6 +78,7 @@ if (!isset($navAnchors) || !is_array($navAnchors)) {
<?php endforeach; ?>
</nav>
<!-- Language Switcher -->
<div class="relative">
<button id="langCurrent"
type="button"
@@ -84,19 +119,22 @@ if (!isset($navAnchors) || !is_array($navAnchors)) {
</div>
<!-- Login Button / Avatar -->
<a href="/login/?lang=<?= htmlspecialchars($lang) ?>"
id="loginButton"
class="relative inline-flex items-center justify-center rounded-full bg-brand-primary px-4 py-1.5 text-xs font-semibold uppercase tracking-[0.18em] text-brand-bg shadow-soft hover:bg-cyan-400 transition-colors"
data-i18n="header_btn_login">
Login
</a>
<button id="userAvatar"
class="hidden h-9 w-9 rounded-full border border-brand-border bg-brand-surface flex items-center justify-center text-xs font-semibold text-brand-text shadow-soft hover:border-brand-primary transition"
aria-label="Mein Konto">
<span><?= strtoupper(substr($userInitials ?? 'U', 0, 2)) ?></span>
</button>
<?php if (!$isLoggedIn): ?>
<!-- Nicht eingeloggt: Login-Button anzeigen -->
<button id="loginButton"
class="relative inline-flex items-center justify-center rounded-full bg-brand-primary px-4 py-1.5 text-xs font-semibold uppercase tracking-[0.18em] text-brand-bg shadow-soft hover:bg-cyan-400 transition-colors"
data-i18n="header_btn_login">
Login
</button>
<?php else: ?>
<!-- Eingeloggt: Avatar anzeigen -->
<button id="userAvatar"
class="h-9 w-9 rounded-full border border-brand-border bg-brand-surface flex items-center justify-center text-xs font-semibold text-brand-text shadow-soft hover:border-brand-primary transition"
aria-label="Mein Konto">
<span><?= htmlspecialchars($userInitials) ?></span>
</button>
<?php endif; ?>
</div>
</div>
</header>