Replace Discord avatar sync with self-service profile picture upload
Drops the Discord-derived avatar entirely (discord_avatar, discord_refresh_token, discord_avatar_synced_at and the background refresh via OAuth refresh token) in favor of members uploading their own picture. "Mein Profil" now shows a larger (120px) avatar with a pencil button pinned to its top-right corner; picking a file uploads it immediately. Uploads are validated by actual image content (getimagesize, not the original filename/extension) and stored under a randomly generated name in assets/uploads/avatars/, which ships with its own .htaccess disabling script execution so a disguised upload can never run as PHP. Falls back to the existing letter placeholder when no picture is set. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
1c9aa0761f
commit
08db95f3a3
12 changed files with 161 additions and 169 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1 +1,4 @@
|
|||
config.php
|
||||
assets/uploads/avatars/*
|
||||
!assets/uploads/avatars/.htaccess
|
||||
!assets/uploads/avatars/.gitkeep
|
||||
|
|
|
|||
27
README.md
27
README.md
|
|
@ -107,25 +107,20 @@ die Raids sehen sollen (z.B. Administrator und Mitglied). Bei einer frischen Ins
|
|||
|
||||
Mitglieder verknüpfen ihren Account danach selbst über einen Button im Dashboard.
|
||||
|
||||
Falls die Datenbank schon vor dem Profilbild-Update existierte, fehlt zusätzlich die Spalte
|
||||
`discord_avatar` (das Profilbild wird sonst nicht angezeigt, auch nicht bei bereits verknüpften
|
||||
Discord-Accounts):
|
||||
```sql
|
||||
ALTER TABLE users ADD COLUMN discord_avatar VARCHAR(64) NULL AFTER discord_username;
|
||||
```
|
||||
Bereits verknüpfte Mitglieder müssen die Discord-Verknüpfung danach einmal in "Mein Profil"
|
||||
trennen und neu herstellen, damit der Avatar-Hash nachträglich gespeichert wird.
|
||||
### Profilbilder einrichten
|
||||
|
||||
Falls die Datenbank schon vor dem automatischen Avatar-Abgleich existierte, fehlen zusätzlich
|
||||
`discord_refresh_token` und `discord_avatar_synced_at` (das Profilbild wird dann beim Öffnen von
|
||||
"Mein Profil" nicht automatisch aktualisiert, wenn sich das Discord-Profilbild ändert):
|
||||
Mitglieder können unter "Mein Profil" ein eigenes Profilbild hochladen (Bleistift-Icon am
|
||||
Avatar). Ohne eigenes Bild zeigt die Seite einen Platzhalter mit dem Anfangsbuchstaben des
|
||||
Anzeigenamens.
|
||||
|
||||
1. Falls die Datenbank schon vor diesem Update existierte, fehlt die Spalte `avatar_filename`:
|
||||
```sql
|
||||
ALTER TABLE users ADD COLUMN discord_refresh_token VARCHAR(255) NULL AFTER discord_avatar;
|
||||
ALTER TABLE users ADD COLUMN discord_avatar_synced_at DATETIME NULL AFTER discord_refresh_token;
|
||||
ALTER TABLE users ADD COLUMN avatar_filename VARCHAR(255) NULL AFTER discord_username;
|
||||
```
|
||||
Auch hier müssen bereits verknüpfte Mitglieder die Discord-Verknüpfung einmal trennen und neu
|
||||
herstellen, damit ein Refresh-Token gespeichert wird (ohne das kann nicht automatisch aktualisiert
|
||||
werden).
|
||||
2. Der Ordner `assets/uploads/avatars/` muss für den Webserver beschreibbar sein (z.B. Rechte
|
||||
`755`/`775`, je nach Hoster). Er wird beim ersten Upload automatisch befüllt; die enthaltene
|
||||
`.htaccess` sorgt dafür, dass hochgeladene Dateien dort niemals als PHP ausgeführt werden
|
||||
können, selbst wenn sich jemand an der Typ-Prüfung vorbeimogelt.
|
||||
|
||||
### Raid-Anmeldung über die Website
|
||||
|
||||
|
|
|
|||
|
|
@ -178,6 +178,32 @@ a:hover { color: var(--gold-hover); text-decoration: underline; }
|
|||
.hero .avatar,
|
||||
.hero .avatar-wrap { margin-bottom: 1rem; }
|
||||
|
||||
.avatar-edit-wrap {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.avatar-edit-btn {
|
||||
position: absolute;
|
||||
top: -2px;
|
||||
right: -2px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 50%;
|
||||
background: var(--gold);
|
||||
color: #1a1a1a;
|
||||
border: 2px solid var(--bg-panel);
|
||||
cursor: pointer;
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
|
||||
.avatar-edit-btn:hover { background: var(--gold-hover); }
|
||||
.avatar-edit-btn .icon { width: 15px; height: 15px; }
|
||||
|
||||
.app-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
|
|
|||
0
assets/uploads/avatars/.gitkeep
Normal file
0
assets/uploads/avatars/.gitkeep
Normal file
17
assets/uploads/avatars/.htaccess
Normal file
17
assets/uploads/avatars/.htaccess
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Hochgeladene Profilbilder duerfen niemals als Skript ausgefuehrt werden,
|
||||
# selbst wenn eine Datei die Typ-/Groessenpruefung in profile.php umgehen sollte.
|
||||
<IfModule mod_php.c>
|
||||
php_flag engine off
|
||||
</IfModule>
|
||||
<IfModule mod_php7.c>
|
||||
php_flag engine off
|
||||
</IfModule>
|
||||
|
||||
<FilesMatch "\.(php|phtml|php[0-9]?|phar|cgi|pl)$">
|
||||
<IfModule mod_authz_core.c>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !mod_authz_core.c>
|
||||
Deny from all
|
||||
</IfModule>
|
||||
</FilesMatch>
|
||||
|
|
@ -22,10 +22,8 @@ try {
|
|||
$discordUser = discord_exchange_code($code);
|
||||
$user = current_user();
|
||||
|
||||
$stmt = db()->prepare(
|
||||
'UPDATE users SET discord_id = ?, discord_username = ?, discord_avatar = ?, discord_refresh_token = ?, discord_avatar_synced_at = NOW() WHERE id = ?'
|
||||
);
|
||||
$stmt->execute([$discordUser['id'], $discordUser['username'], $discordUser['avatar'], $discordUser['refresh_token'], $user['id']]);
|
||||
$stmt = db()->prepare('UPDATE users SET discord_id = ?, discord_username = ? WHERE id = ?');
|
||||
$stmt->execute([$discordUser['id'], $discordUser['username'], $user['id']]);
|
||||
|
||||
set_flash('success', 'Discord-Account "' . $discordUser['username'] . '" wurde verknüpft.');
|
||||
} catch (PDOException $e) {
|
||||
|
|
|
|||
|
|
@ -8,9 +8,7 @@ if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|||
verify_csrf();
|
||||
|
||||
$user = current_user();
|
||||
db()->prepare(
|
||||
'UPDATE users SET discord_id = NULL, discord_username = NULL, discord_avatar = NULL, discord_refresh_token = NULL, discord_avatar_synced_at = NULL WHERE id = ?'
|
||||
)->execute([$user['id']]);
|
||||
db()->prepare('UPDATE users SET discord_id = NULL, discord_username = NULL WHERE id = ?')->execute([$user['id']]);
|
||||
|
||||
set_flash('success', 'Discord-Verknüpfung wurde entfernt.');
|
||||
redirect('/dashboard.php');
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ function current_user(): ?array
|
|||
return null;
|
||||
}
|
||||
|
||||
$stmt = db()->prepare('SELECT id, username, display_name, status, must_change_password, discord_id, discord_username, discord_avatar, discord_refresh_token, discord_avatar_synced_at FROM users WHERE id = ?');
|
||||
$stmt = db()->prepare('SELECT id, username, display_name, status, must_change_password, discord_id, discord_username, avatar_filename FROM users WHERE id = ?');
|
||||
$stmt->execute([$_SESSION['user_id']]);
|
||||
$row = $stmt->fetch();
|
||||
|
||||
|
|
|
|||
|
|
@ -39,48 +39,11 @@ function discord_authorize_url(string $state): string
|
|||
return 'https://discord.com/oauth2/authorize?' . http_build_query($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ruft mit einem OAuth-Access-Token die Discord-Identitaet
|
||||
* (ID + Benutzername + Avatar-Hash) ab.
|
||||
*
|
||||
* @return array{id: string, username: string, avatar: ?string}
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
function discord_fetch_user(string $accessToken): array
|
||||
{
|
||||
$ch = curl_init('https://discord.com/api/users/@me');
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $accessToken],
|
||||
CURLOPT_TIMEOUT => 10,
|
||||
]);
|
||||
$userResponse = curl_exec($ch);
|
||||
$userHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($userResponse === false || $userHttpCode !== 200) {
|
||||
throw new RuntimeException('Discord-Benutzerdaten konnten nicht abgerufen werden.');
|
||||
}
|
||||
|
||||
$userData = json_decode($userResponse, true);
|
||||
if (!is_array($userData) || empty($userData['id']) || !isset($userData['username'])) {
|
||||
throw new RuntimeException('Unerwartete Antwort von Discord.');
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => (string) $userData['id'],
|
||||
'username' => (string) $userData['username'],
|
||||
'avatar' => isset($userData['avatar']) && $userData['avatar'] !== null ? (string) $userData['avatar'] : null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tauscht den OAuth-Code gegen ein Access-Token und liest damit die
|
||||
* Discord-Identitaet aus. Das Refresh-Token wird mitgeliefert, damit
|
||||
* Benutzername/Avatar spaeter ohne erneuten Login-Dialog aktualisiert
|
||||
* werden koennen (siehe discord_refresh_identity()).
|
||||
* Discord-Identitaet (ID + Benutzername) aus.
|
||||
*
|
||||
* @return array{id: string, username: string, avatar: ?string, refresh_token: string}
|
||||
* @return array{id: string, username: string}
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
function discord_exchange_code(string $code): array
|
||||
|
|
@ -119,98 +82,27 @@ function discord_exchange_code(string $code): array
|
|||
throw new RuntimeException('Discord hat den Login-Code nicht akzeptiert.');
|
||||
}
|
||||
|
||||
$userInfo = discord_fetch_user((string) $tokenData['access_token']);
|
||||
$userInfo['refresh_token'] = (string) ($tokenData['refresh_token'] ?? '');
|
||||
|
||||
return $userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erneuert Benutzername/Avatar ueber das gespeicherte Refresh-Token, ohne dass
|
||||
* der Nutzer den Discord-Login-Dialog erneut durchlaufen muss. Discord rotiert
|
||||
* das Refresh-Token bei jeder Nutzung, deshalb wird das neue mit zurueckgegeben
|
||||
* und muss anstelle des alten gespeichert werden.
|
||||
*
|
||||
* @return array{id: string, username: string, avatar: ?string, refresh_token: string}
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
function discord_refresh_identity(string $refreshToken): array
|
||||
{
|
||||
if (!function_exists('curl_init')) {
|
||||
throw new RuntimeException('Die PHP-cURL-Erweiterung ist auf diesem Server nicht aktiviert.');
|
||||
}
|
||||
|
||||
$config = discord_config();
|
||||
|
||||
$ch = curl_init('https://discord.com/api/oauth2/token');
|
||||
curl_setopt_array($ch, [
|
||||
$ch2 = curl_init('https://discord.com/api/users/@me');
|
||||
curl_setopt_array($ch2, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => http_build_query([
|
||||
'client_id' => $config['client_id'],
|
||||
'client_secret' => $config['client_secret'],
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => $refreshToken,
|
||||
]),
|
||||
CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded'],
|
||||
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $tokenData['access_token']],
|
||||
CURLOPT_TIMEOUT => 10,
|
||||
]);
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curlError = curl_error($ch);
|
||||
curl_close($ch);
|
||||
$userResponse = curl_exec($ch2);
|
||||
$userHttpCode = curl_getinfo($ch2, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch2);
|
||||
|
||||
if ($response === false) {
|
||||
throw new RuntimeException('Verbindung zu Discord fehlgeschlagen: ' . $curlError);
|
||||
if ($userResponse === false || $userHttpCode !== 200) {
|
||||
throw new RuntimeException('Discord-Benutzerdaten konnten nicht abgerufen werden.');
|
||||
}
|
||||
|
||||
$tokenData = json_decode($response, true);
|
||||
if ($httpCode !== 200 || !is_array($tokenData) || empty($tokenData['access_token'])) {
|
||||
throw new RuntimeException('Discord-Token konnte nicht erneuert werden (Verknuepfung eventuell widerrufen).');
|
||||
$userData = json_decode($userResponse, true);
|
||||
if (!is_array($userData) || empty($userData['id']) || !isset($userData['username'])) {
|
||||
throw new RuntimeException('Unerwartete Antwort von Discord.');
|
||||
}
|
||||
|
||||
$userInfo = discord_fetch_user((string) $tokenData['access_token']);
|
||||
$userInfo['refresh_token'] = (string) ($tokenData['refresh_token'] ?? $refreshToken);
|
||||
|
||||
return $userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert Benutzername/Avatar im Hintergrund per Refresh-Token, falls der
|
||||
* letzte Abgleich laenger als eine Stunde her ist. Damit muessen Mitglieder
|
||||
* ihre Discord-Verknuepfung nicht manuell erneuern, wenn sie ihr Profilbild
|
||||
* auf Discord aendern - der naechste Aufruf von "Mein Profil" zieht es nach.
|
||||
* Schlaegt der Refresh fehl (z.B. Verknuepfung auf Discord-Seite widerrufen),
|
||||
* bleibt der zuletzt bekannte Stand unveraendert; es wird lediglich der
|
||||
* Zeitstempel gesetzt, damit nicht bei jedem Aufruf erneut versucht wird.
|
||||
*
|
||||
* @param array<string, mixed> $user
|
||||
*/
|
||||
function discord_sync_avatar_if_stale(array &$user): void
|
||||
{
|
||||
if (empty($user['discord_id']) || empty($user['discord_refresh_token'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$syncedAt = $user['discord_avatar_synced_at'] ?? null;
|
||||
if ($syncedAt !== null && strtotime((string) $syncedAt) > time() - 3600) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$fresh = discord_refresh_identity((string) $user['discord_refresh_token']);
|
||||
} catch (Throwable $e) {
|
||||
db()->prepare('UPDATE users SET discord_avatar_synced_at = NOW() WHERE id = ?')->execute([$user['id']]);
|
||||
$user['discord_avatar_synced_at'] = date('Y-m-d H:i:s');
|
||||
return;
|
||||
}
|
||||
|
||||
db()->prepare(
|
||||
'UPDATE users SET discord_username = ?, discord_avatar = ?, discord_refresh_token = ?, discord_avatar_synced_at = NOW() WHERE id = ?'
|
||||
)->execute([$fresh['username'], $fresh['avatar'], $fresh['refresh_token'], $user['id']]);
|
||||
|
||||
$user['discord_username'] = $fresh['username'];
|
||||
$user['discord_avatar'] = $fresh['avatar'];
|
||||
$user['discord_refresh_token'] = $fresh['refresh_token'];
|
||||
$user['discord_avatar_synced_at'] = date('Y-m-d H:i:s');
|
||||
return [
|
||||
'id' => (string) $userData['id'],
|
||||
'username' => (string) $userData['username'],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,13 +132,12 @@ function discord_logo(int $size = 24): string
|
|||
. 'fill="currentColor" aria-hidden="true"><path d="' . $path . '"/></svg>';
|
||||
}
|
||||
|
||||
// Profilbild: Discord-Avatar, falls verknuepft und gesetzt, sonst ein
|
||||
// Platzhalter mit dem Anfangsbuchstaben des Anzeigenamens auf einem
|
||||
// nutzerfest zugeordneten Hintergrund aus einer zur Lumina-Optik passenden Palette.
|
||||
// Profilbild: selbst hochgeladenes Bild, falls vorhanden, sonst ein Platzhalter
|
||||
// mit dem Anfangsbuchstaben des Anzeigenamens auf einem nutzerfest zugeordneten
|
||||
// Hintergrund aus einer zur Lumina-Optik passenden Palette.
|
||||
// Der Platzhalter wird zusaetzlich immer mitgerendert (nur unsichtbar), damit
|
||||
// bei einem fehlschlagenden Discord-Bild (abgelaufener Hash, Netzwerk-/
|
||||
// Trackingblocker o.ae.) per onerror automatisch darauf zurueckgefallen wird,
|
||||
// statt ein kaputtes Bild-Icon anzuzeigen.
|
||||
// bei einem fehlenden/kaputten Bild per onerror automatisch darauf
|
||||
// zurueckgefallen wird, statt ein kaputtes Bild-Icon anzuzeigen.
|
||||
function avatar_html(array $user, int $size = 40): string
|
||||
{
|
||||
static $palette = ['#4f6f52', '#6a4c93', '#1b6ca8', '#b5533c', '#8a6d3b', '#3f6c86', '#4a5568', '#a4443a'];
|
||||
|
|
@ -153,19 +152,17 @@ function avatar_html(array $user, int $size = 40): string
|
|||
$color = $palette[crc32($seed) % count($palette)];
|
||||
$fontSize = round($size * 0.42, 1);
|
||||
|
||||
$hasDiscordAvatar = !empty($user['discord_id']) && !empty($user['discord_avatar']);
|
||||
$hasCustomAvatar = !empty($user['avatar_filename']);
|
||||
|
||||
$placeholderStyle = 'width:' . $size . 'px;height:' . $size . 'px;background:' . e($color) . ';font-size:' . $fontSize . 'px;'
|
||||
. ($hasDiscordAvatar ? 'display:none;' : '');
|
||||
. ($hasCustomAvatar ? 'display:none;' : '');
|
||||
$placeholder = '<span class="avatar avatar-placeholder" style="' . $placeholderStyle . '">' . e($letter) . '</span>';
|
||||
|
||||
if (!$hasDiscordAvatar) {
|
||||
if (!$hasCustomAvatar) {
|
||||
return $placeholder;
|
||||
}
|
||||
|
||||
$ext = str_starts_with((string) $user['discord_avatar'], 'a_') ? 'gif' : 'png';
|
||||
$url = 'https://cdn.discordapp.com/avatars/' . rawurlencode((string) $user['discord_id'])
|
||||
. '/' . rawurlencode((string) $user['discord_avatar']) . '.' . $ext . '?size=' . ($size * 2);
|
||||
$url = '/assets/uploads/avatars/' . rawurlencode((string) $user['avatar_filename']);
|
||||
|
||||
return '<span class="avatar-wrap">'
|
||||
. '<img class="avatar" src="' . e($url) . '" alt="" width="' . $size . '" height="' . $size . '" '
|
||||
|
|
|
|||
74
profile.php
74
profile.php
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/includes/bootstrap.php';
|
||||
require_once __DIR__ . '/includes/discord.php';
|
||||
require_login();
|
||||
|
||||
$user = current_user();
|
||||
discord_sync_avatar_if_stale($user);
|
||||
$profileError = null;
|
||||
$passwordError = null;
|
||||
$avatarError = null;
|
||||
$avatarUploadDir = __DIR__ . '/assets/uploads/avatars/';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
verify_csrf();
|
||||
|
|
@ -36,6 +36,47 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
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);
|
||||
|
||||
if (move_uploaded_file($file['tmp_name'], $avatarUploadDir . $filename)) {
|
||||
$oldFilename = $user['avatar_filename'] ?? null;
|
||||
db()->prepare('UPDATE users SET avatar_filename = ? 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 = 'Datei konnte nicht gespeichert werden (Berechtigungen auf dem Server prüfen).';
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($action === 'remove_avatar') {
|
||||
$oldFilename = $user['avatar_filename'] ?? null;
|
||||
db()->prepare('UPDATE users SET avatar_filename = NULL WHERE id = ?')->execute([$user['id']]);
|
||||
if ($oldFilename && is_file($avatarUploadDir . $oldFilename)) {
|
||||
@unlink($avatarUploadDir . $oldFilename);
|
||||
}
|
||||
set_flash('success', 'Profilbild wurde entfernt.');
|
||||
redirect('/profile.php');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -44,13 +85,40 @@ include __DIR__ . '/includes/header.php';
|
|||
?>
|
||||
<div class="panel">
|
||||
<div class="profile-header">
|
||||
<?= avatar_html($user, 72) ?>
|
||||
<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['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">
|
||||
|
|
|
|||
|
|
@ -12,9 +12,7 @@ CREATE TABLE IF NOT EXISTS users (
|
|||
must_change_password TINYINT(1) NOT NULL DEFAULT 0,
|
||||
discord_id BIGINT UNSIGNED NULL UNIQUE,
|
||||
discord_username VARCHAR(100) NULL,
|
||||
discord_avatar VARCHAR(64) NULL,
|
||||
discord_refresh_token VARCHAR(255) NULL,
|
||||
discord_avatar_synced_at DATETIME NULL,
|
||||
avatar_filename VARCHAR(255) NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
last_login DATETIME NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
|
|
|||
Loading…
Reference in a new issue