LuminaWebsite/discord_callback.php
Maaxxs 08db95f3a3 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>
2026-09-19 07:34:47 +02:00

35 lines
1.3 KiB
PHP

<?php
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/discord.php';
require_login();
$state = (string) ($_GET['state'] ?? '');
$code = (string) ($_GET['code'] ?? '');
$expectedState = (string) ($_SESSION['discord_oauth_state'] ?? '');
unset($_SESSION['discord_oauth_state']);
if (!empty($_GET['error'])) {
set_flash('error', 'Discord-Verknüpfung wurde abgebrochen.');
redirect('/dashboard.php');
}
if ($code === '' || $state === '' || $expectedState === '' || !hash_equals($expectedState, $state)) {
set_flash('error', 'Ungültige Antwort von Discord. Bitte erneut versuchen.');
redirect('/dashboard.php');
}
try {
$discordUser = discord_exchange_code($code);
$user = current_user();
$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) {
set_flash('error', 'Dieser Discord-Account ist bereits mit einem anderen Benutzer verknüpft.');
} catch (Throwable $e) {
set_flash('error', 'Discord-Verknüpfung fehlgeschlagen: ' . $e->getMessage());
}
redirect('/dashboard.php');