Anzeigename and Passwort ändern now sit in a two-column grid (stacks on narrow screens). The Discord section gets its own bordered card with the official Discord mark (inline SVG, brand blurple accent) and a clear Verbunden/Nicht verbunden status badge, replacing the plain generic panel. Verified both connection states with a rendered screenshot. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
113 lines
4.5 KiB
PHP
113 lines
4.5 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/bootstrap.php';
|
|
require_login();
|
|
|
|
$user = current_user();
|
|
$profileError = null;
|
|
$passwordError = null;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
verify_csrf();
|
|
$action = (string) ($_POST['action'] ?? '');
|
|
|
|
if ($action === 'update_profile') {
|
|
$displayName = trim((string) ($_POST['display_name'] ?? ''));
|
|
if ($displayName === '') {
|
|
$profileError = 'Anzeigename darf nicht leer sein.';
|
|
} else {
|
|
db()->prepare('UPDATE users SET display_name = ? WHERE id = ?')->execute([$displayName, $user['id']]);
|
|
set_flash('success', 'Profil wurde aktualisiert.');
|
|
redirect('/profile.php');
|
|
}
|
|
$user['display_name'] = $displayName;
|
|
} elseif ($action === 'change_password') {
|
|
$newPassword = (string) ($_POST['new_password'] ?? '');
|
|
$newPasswordConfirm = (string) ($_POST['new_password_confirm'] ?? '');
|
|
|
|
if (strlen($newPassword) < 8) {
|
|
$passwordError = 'Das neue Passwort muss mindestens 8 Zeichen lang sein.';
|
|
} elseif ($newPassword !== $newPasswordConfirm) {
|
|
$passwordError = 'Die Passwörter stimmen nicht überein.';
|
|
} else {
|
|
db()->prepare('UPDATE users SET password_hash = ?, must_change_password = 0 WHERE id = ?')
|
|
->execute([password_hash($newPassword, PASSWORD_DEFAULT), $user['id']]);
|
|
set_flash('success', 'Passwort wurde geändert.');
|
|
redirect('/profile.php');
|
|
}
|
|
}
|
|
}
|
|
|
|
$pageTitle = 'Mein Profil';
|
|
include __DIR__ . '/includes/header.php';
|
|
?>
|
|
<div class="panel">
|
|
<h1>Mein Profil</h1>
|
|
<p class="text-muted">Benutzername: <strong><?= e($user['username']) ?></strong></p>
|
|
</div>
|
|
|
|
<div class="profile-grid">
|
|
<div class="panel">
|
|
<h2>Anzeigename</h2>
|
|
<?php if ($profileError): ?>
|
|
<div class="flash flash-error"><?= e($profileError) ?></div>
|
|
<?php endif; ?>
|
|
<form method="post" action="/profile.php">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="action" value="update_profile">
|
|
<div>
|
|
<label for="display_name">Anzeigename</label>
|
|
<input type="text" id="display_name" name="display_name" value="<?= e($user['display_name']) ?>" required>
|
|
</div>
|
|
<button type="submit">Speichern</button>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="panel">
|
|
<h2>Passwort ändern</h2>
|
|
<?php if ($passwordError): ?>
|
|
<div class="flash flash-error"><?= e($passwordError) ?></div>
|
|
<?php endif; ?>
|
|
<form method="post" action="/profile.php">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="action" value="change_password">
|
|
<div>
|
|
<label for="new_password">Neues Passwort</label>
|
|
<input type="password" id="new_password" name="new_password" required>
|
|
<div class="field-hint">Mindestens 8 Zeichen.</div>
|
|
</div>
|
|
<div>
|
|
<label for="new_password_confirm">Neues Passwort wiederholen</label>
|
|
<input type="password" id="new_password_confirm" name="new_password_confirm" required>
|
|
</div>
|
|
<button type="submit">Passwort speichern</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="panel discord-card">
|
|
<div class="discord-card-header">
|
|
<?= discord_logo(40) ?>
|
|
<div>
|
|
<h2>Discord</h2>
|
|
<?php if (!empty($user['discord_id'])): ?>
|
|
<span class="badge badge-active">Verbunden</span>
|
|
<?php else: ?>
|
|
<span class="badge badge-disabled">Nicht verbunden</span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php if (!empty($user['discord_id'])): ?>
|
|
<p>Verknüpft als <strong><?= e((string) $user['discord_username']) ?></strong></p>
|
|
<form method="post" action="/discord_unlink.php" class="inline-form" onsubmit="return confirm('Discord-Verknüpfung wirklich entfernen?');">
|
|
<?= csrf_field() ?>
|
|
<button type="submit" class="button-secondary">Verknüpfung entfernen</button>
|
|
</form>
|
|
<?php else: ?>
|
|
<p class="text-muted">Verknüpfe deinen Discord-Account, um dich über die Website zu Raids anmelden zu können.</p>
|
|
<a class="button discord-connect-button" href="/discord_login.php">
|
|
<?= discord_logo(18) ?> Mit Discord verknüpfen
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php include __DIR__ . '/includes/footer.php'; ?>
|