LuminaWebsite/profile.php
Maaxxs 9c955af902 Profile page: symmetric boxes and buttons, character level limited to 45
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 09:49:47 +02:00

286 lines
15 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once __DIR__ . '/includes/bootstrap.php';
require_login();
$user = current_user();
$profileError = null;
$passwordError = null;
$avatarError = null;
$avatarUploadDir = __DIR__ . '/assets/uploads/avatars/';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
verify_csrf();
$action = (string) ($_POST['action'] ?? '');
if ($action === 'update_profile') {
$displayName = trim((string) ($_POST['display_name'] ?? ''));
// Mit Discord-Verknuepfung folgt der Anzeigename dem Namen auf dem Discord-Server.
if (!empty($user['discord_id'])) {
$displayName = (string) $user['display_name'];
}
$className = (string) ($_POST['class_name'] ?? '');
$className = in_array($className, AION_CLASSES, true) ? $className : null;
if ($displayName === '') {
$profileError = 'Anzeigename darf nicht leer sein.';
} else {
db()->prepare('UPDATE users SET display_name = ?, class_name = ? WHERE id = ?')->execute([$displayName, $className, $user['id']]);
set_flash('success', 'Profil wurde aktualisiert.');
redirect('/profile.php');
}
$user['display_name'] = $displayName;
} elseif ($action === 'change_password' && !empty($user['password_login'])) {
$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');
}
} elseif ($action === 'update_avatar') {
$file = $_FILES['avatar'] ?? null;
$allowedTypes = [IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_WEBP];
if (!$file || ($file['error'] ?? UPLOAD_ERR_NO_FILE) === UPLOAD_ERR_NO_FILE) {
$avatarError = 'Bitte eine Bilddatei auswählen.';
} elseif ($file['error'] !== UPLOAD_ERR_OK) {
$avatarError = 'Upload fehlgeschlagen.';
} elseif ($file['size'] > 3 * 1024 * 1024) {
$avatarError = 'Die Datei ist zu groß (max. 3 MB).';
} else {
// Dateityp wird ausschließlich am tatsaechlichen Bildinhalt erkannt (nicht am
// Originalnamen), die Endung selbst erzeugt - so kann keine ausfuehrbare Datei
// unter falschem Namen/falscher Endung eingeschleust werden.
$imageInfo = @getimagesize($file['tmp_name']);
if ($imageInfo === false || !in_array($imageInfo[2], $allowedTypes, true)) {
$avatarError = 'Nur JPG, PNG, GIF oder WEBP sind als Profilbild erlaubt.';
} else {
$filename = 'user' . $user['id'] . '_' . bin2hex(random_bytes(8)) . '.' . image_type_to_extension($imageInfo[2], false);
// Neu rechnen (entfernt angehaengten Code/EXIF) und auf 512 px begrenzen
$storeError = store_uploaded_image($file['tmp_name'], $avatarUploadDir . $filename, $imageInfo[2], 512);
if ($storeError === null) {
$oldFilename = $user['avatar_filename'] ?? null;
// Eigenes Bild: nicht mehr vom Discord-Profilbild ueberschreiben lassen.
db()->prepare('UPDATE users SET avatar_filename = ?, avatar_sync = 0, discord_avatar = NULL WHERE id = ?')
->execute([$filename, $user['id']]);
if ($oldFilename && is_file($avatarUploadDir . $oldFilename)) {
@unlink($avatarUploadDir . $oldFilename);
}
set_flash('success', 'Profilbild wurde aktualisiert.');
redirect('/profile.php');
} else {
$avatarError = $storeError;
}
}
}
} elseif ($action === 'restart_tour') {
// Einfuehrung zuruecksetzen - sie startet beim naechsten Aufruf des Dashboards.
db()->prepare('UPDATE users SET tour_completed_at = NULL WHERE id = ?')->execute([$user['id']]);
redirect('/dashboard.php');
} elseif ($action === 'use_discord_avatar' && !empty($user['discord_id'])) {
// Wieder das Discord-Profilbild verwenden: eigenes Bild weg, Übernahme an, sofort abgleichen.
$oldFilename = $user['avatar_filename'] ?? null;
db()->prepare('UPDATE users SET avatar_filename = NULL, avatar_sync = 1, discord_avatar = NULL WHERE id = ?')
->execute([$user['id']]);
if ($oldFilename && is_file($avatarUploadDir . $oldFilename)) {
@unlink($avatarUploadDir . $oldFilename);
}
$result = discord_live_check((int) $user['id'], true);
set_flash($result === 'ok' ? 'success' : 'info', $result === 'ok'
? 'Dein Discord-Profilbild wird jetzt verwendet und bleibt automatisch aktuell.'
: 'Dein Discord-Profilbild wird ab der nächsten Discord-Anmeldung übernommen.');
redirect('/profile.php');
} elseif ($action === 'remove_avatar') {
$oldFilename = $user['avatar_filename'] ?? null;
// Bewusst kein Bild: auch nicht wieder von Discord holen.
db()->prepare('UPDATE users SET avatar_filename = NULL, avatar_sync = 0, discord_avatar = NULL WHERE id = ?')->execute([$user['id']]);
if ($oldFilename && is_file($avatarUploadDir . $oldFilename)) {
@unlink($avatarUploadDir . $oldFilename);
}
set_flash('success', 'Profilbild wurde entfernt.');
redirect('/profile.php');
}
}
$pageTitle = 'Mein Profil';
include __DIR__ . '/includes/header.php';
?>
<div class="panel">
<div class="profile-header">
<div class="avatar-edit-wrap">
<?= avatar_html($user, 120) ?>
<label class="avatar-edit-btn" for="avatar-upload-input" title="Profilbild ändern">
<?= icon('edit') ?>
</label>
</div>
<div>
<h1>Mein Profil</h1>
<p class="text-muted">Benutzername: <strong><?= e($user['username']) ?></strong></p>
<?php if ($avatarError): ?>
<p class="flash flash-error" style="margin-top:0.5rem;"><?= e($avatarError) ?></p>
<?php endif; ?>
<?php if (!empty($user['discord_id']) && !empty($user['avatar_sync'])): ?>
<p class="avatar-sync-hint"><?= discord_logo(14) ?> Dein Profilbild wird automatisch von Discord übernommen. Lädst du ein eigenes hoch, bleibt dieses bestehen.</p>
<?php elseif (!empty($user['discord_id'])): ?>
<form method="post" action="/profile.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="use_discord_avatar">
<button type="submit" class="button-secondary button-small avatar-sync-button"><?= discord_logo(14) ?> Discord-Profilbild verwenden</button>
</form>
<?php endif; ?>
<?php if (!empty($user['avatar_filename'])): ?>
<form method="post" action="/profile.php" class="inline-form" onsubmit="return confirm('Profilbild wirklich entfernen?');">
<?= csrf_field() ?>
<input type="hidden" name="action" value="remove_avatar">
<button type="submit" class="text-button" style="font-size:0.85rem;margin-top:0.4rem;">Profilbild entfernen</button>
</form>
<?php endif; ?>
</div>
</div>
<form id="avatar-upload-form" method="post" action="/profile.php" enctype="multipart/form-data" style="display:none;">
<?= csrf_field() ?>
<input type="hidden" name="action" value="update_avatar">
<input type="file" id="avatar-upload-input" name="avatar" accept="image/png,image/jpeg,image/gif,image/webp">
</form>
</div>
<script>
document.getElementById('avatar-upload-input').addEventListener('change', function () {
if (this.files && this.files.length) {
document.getElementById('avatar-upload-form').submit();
}
});
</script>
<div class="profile-grid">
<div class="panel profile-card">
<h2>Anzeigename</h2>
<?php if ($profileError): ?>
<div class="flash flash-error"><?= e($profileError) ?></div>
<?php endif; ?>
<form method="post" action="/profile.php" class="profile-card-form">
<?= 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<?= !empty($user['discord_id']) ? ' readonly' : '' ?>>
<?php if (!empty($user['discord_id'])): ?>
<div class="field-hint"><?= discord_logo(12) ?> Wird automatisch von deinem Namen auf unserem Discord-Server übernommen. Ändern kannst du ihn dort über „Server-Profil bearbeiten“.</div>
<?php endif; ?>
</div>
<div>
<label for="class_name">Klasse</label>
<div class="class-select-row">
<select id="class_name" name="class_name">
<option value="">– keine –</option>
<?php foreach (AION_CLASSES as $class): ?>
<option value="<?= e($class) ?>"<?= ($user['class_name'] ?? '') === $class ? ' selected' : '' ?>><?= e($class) ?></option>
<?php endforeach; ?>
</select>
<?= class_badge_html($user['class_name'] ?? null, 32) ?>
</div>
<div class="field-hint">
Wird als Icon hinter deinem Namen angezeigt, z.B. in der Mitgliederliste.
<?php if (!empty($user['discord_id'])): ?>
Hast du auf unserem Discord eine Klassenrolle gewählt, wird sie automatisch übernommen.
<?php endif; ?>
</div>
</div>
<button type="submit" class="profile-card-button">Speichern</button>
</form>
</div>
<?php if (!empty($user['password_login'])): ?>
<div class="panel profile-card">
<h2>Passwort ändern</h2>
<?php if ($passwordError): ?>
<div class="flash flash-error"><?= e($passwordError) ?></div>
<?php endif; ?>
<form method="post" action="/profile.php" class="profile-card-form">
<?= 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" class="profile-card-button">Passwort speichern</button>
</form>
</div>
<?php else: ?>
<div class="panel profile-card">
<h2>Anmeldung</h2>
<p class="text-muted">Du meldest dich über Discord an. Die Anmeldung mit Benutzername und Passwort ist für dein Konto nicht freigeschaltet - das kann die Legionsleitung bei Bedarf ändern.</p>
</div>
<?php endif; ?>
</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>
<p class="text-muted">Deine Berechtigungsgruppen werden automatisch mit deinen Rollen auf dem Discord-Server abgeglichen.</p>
<?php if (!discord_unlink_allowed()): ?>
<p class="text-muted">Das Lösen der Verknüpfung ist von der Legionsleitung deaktiviert.</p>
<?php elseif (!empty($user['password_login'])): ?>
<form method="post" action="/discord_unlink.php" class="inline-form" onsubmit="return confirm('Discord-Verknüpfung wirklich entfernen? Gruppen, die über Discord-Rollen vergeben werden, gehen dabei verloren.');">
<?= csrf_field() ?>
<button type="submit" class="button-secondary">Verknüpfung entfernen</button>
</form>
<?php endif; ?>
<?php else: ?>
<p class="text-muted">Verknüpfe deinen Discord-Account, um dich über Discord anzumelden, deine Gruppen automatisch aus deinen Discord-Rollen zu bekommen und 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 if (user_has_permission('members.view')): ?>
<div class="panel tour-restart-panel">
<div class="tour-restart">
<span class="icon-badge"><?= icon('users') ?></span>
<div>
<h2>Meine Profilseite</h2>
<p class="text-muted">Deine Seite in der Mitgliederliste: ein Text über dich, deine Charaktere mit Portrait und Bild und eine Bildergalerie.</p>
</div>
<a class="button button-secondary tour-restart-button" href="/member_edit.php">Profilseite gestalten</a>
</div>
</div>
<?php endif; ?>
<div class="panel tour-restart-panel">
<div class="tour-restart">
<span class="icon-badge"><?= icon('route') ?></span>
<div>
<h2>Einführung</h2>
<p class="text-muted">Lass dir das Dashboard noch einmal Schritt für Schritt zeigen - wo du was findest und wofür es gut ist.</p>
</div>
<form method="post" action="/profile.php" class="inline-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="restart_tour">
<button type="submit" class="button button-secondary tour-restart-button">Einführung neu starten</button>
</form>
</div>
</div>
<?php include __DIR__ . '/includes/footer.php'; ?>