LuminaWebsite/discord_unlink.php
Maaxxs 0eb8816ef8 Admin: switch for unlinking Discord, keep table actions in view
The user list gets a switch "Mitglieder dürfen ihre Discord-Verknüpfung im
Profil lösen" (users.edit, default on). Turned off, the profile shows a note
instead of the button and discord_unlink.php refuses the request. The value
lives in a new settings table, created automatically like the other schema
additions (SCHEMA_VERSION 2).

The user and group tables were wider than the 1100px content column, so the
actions column (edit/delete/approve) scrolled out of view. Both pages now
use the wide container and the actions column sticks to the right edge.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 08:00:06 +02:00

33 lines
1.1 KiB
PHP

<?php
require_once __DIR__ . '/includes/bootstrap.php';
require_login();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/profile.php');
}
verify_csrf();
$user = current_user();
if (!discord_unlink_allowed()) {
set_flash('error', 'Das Lösen der Discord-Verknüpfung ist derzeit von der Legionsleitung deaktiviert.');
redirect('/profile.php');
}
// Ohne Passwort-Login waere das Konto danach nicht mehr erreichbar.
if (empty($user['password_login'])) {
set_flash('error', 'Du meldest dich nur über Discord an - ohne Verknüpfung kämst du nicht mehr in dein Konto. Lass dir zuerst den Passwort-Login freischalten.');
redirect('/profile.php');
}
db()->prepare(
'UPDATE users SET discord_id = NULL, discord_username = NULL, discord_access_token = NULL,
discord_refresh_token = NULL, discord_token_expires = NULL, discord_synced_at = NULL
WHERE id = ?'
)->execute([$user['id']]);
// Discord-gesteuerte Gruppen haengen an der Verknuepfung.
discord_sync_roles((int) $user['id'], []);
set_flash('success', 'Discord-Verknüpfung wurde entfernt.');
redirect('/profile.php');