login change
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user