- Data export (Art. 15/20 GDPR, includes/data_export.php): ZIP with daten.json, LIESMICH.txt and the
member's own images (avatar, characters, gallery, bug reports). It covers every table related to the
account plus, via the bot API, raid sign-ups, premades, created events and activity checks. Password hash,
tokens and player reports (they name the reporters) are left out. The ZIP is written by data_export_zip(),
so the PHP zip extension is not needed.
- Members find export and deletion under "Mein Profil" at the very bottom in a collapsed "Konto & Daten"
section (data_export.php, account_delete.php).
- Leadership: new icon "Daten & Löschung" in the user admin (admin/user_export.php, permission users.export).
It downloads the export or creates a download link for someone without access (datenauskunft.php?t=...,
7 days, 5 downloads, only the SHA-256 hash stored in data_export_links). The link page shows a button first,
so link previews don't use up downloads. It also works in maintenance mode.
- Account deletion (includes/account_deletion.php): the account is anonymized instead of removed.
- Deleted: profile, avatar, characters, gallery, gear sets, private tactics, groups, tokens, calendar
participations and bug report images.
- Contributions remain as "Ehemaliges Mitglied" without name or Discord ID.
- Requested by the member (type LÖSCHEN) or by the leadership (users.delete, also immediately).
- Executed after 7 days by account_deletion_run_due(); logging in before that cancels it and tells the member.
- The user admin shows "Löschung am ..." and "Gelöscht (unkenntlich)". Privacy policy, README and a
leadership patch note are updated. Schema v44 (users.deletion_scheduled_at, users.deleted_at, data_export_links).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
234 lines
14 KiB
PHP
234 lines
14 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../includes/bootstrap.php';
|
|
require_permission('users.view');
|
|
|
|
$canCreate = user_has_permission('users.create');
|
|
$canEdit = user_has_permission('users.edit');
|
|
$canDelete = user_has_permission('users.delete');
|
|
$canManageAdmins = user_has_permission('users.admin');
|
|
$canExport = user_has_permission('users.export');
|
|
$currentUser = current_user();
|
|
|
|
$users = db()->query(
|
|
"SELECT u.id, u.username, u.display_name, u.status, u.last_login, u.created_at, u.must_change_password,
|
|
u.password_login, u.is_admin, u.discord_id, u.discord_username, u.deletion_scheduled_at, u.deleted_at,
|
|
MIN(r.roster_order) AS best_rank,
|
|
GROUP_CONCAT(COALESCE(NULLIF(r.display_name, ''), r.name) ORDER BY COALESCE(r.roster_order, 999), r.name SEPARATOR ', ') AS role_names
|
|
FROM users u
|
|
LEFT JOIN user_roles ur ON ur.user_id = u.id
|
|
LEFT JOIN roles r ON r.id = ur.role_id
|
|
GROUP BY u.id"
|
|
)->fetchAll();
|
|
|
|
// Reihenfolge: wer auf die Freischaltung wartet (die Liste, die man abarbeitet), dann
|
|
// Administratoren, Entwickler und danach nach der hoechsten Gruppe - gemessen an der
|
|
// Reihenfolge der Mitgliederliste (kleinere Zahl = hoeher, Gruppen ohne Zahl zuletzt).
|
|
usort($users, static function (array $a, array $b): int {
|
|
$key = static fn (array $u): array => [
|
|
$u['status'] === 'pending' ? 0 : 1,
|
|
!empty($u['is_admin']) ? 0 : 1,
|
|
is_developer($u) ? 0 : 1,
|
|
$u['best_rank'] !== null ? (int) $u['best_rank'] : PHP_INT_MAX,
|
|
mb_strtolower($u['display_name'] !== '' ? $u['display_name'] : $u['username']),
|
|
];
|
|
return $key($a) <=> $key($b);
|
|
});
|
|
|
|
$statusLabels = [
|
|
'active' => ['Aktiv', 'badge-active'],
|
|
'disabled' => ['Deaktiviert', 'badge-disabled'],
|
|
'pending' => ['Wartet auf Freischaltung', 'badge-pending'],
|
|
];
|
|
|
|
$pageTitle = 'Benutzerverwaltung';
|
|
// Die Tabelle hat viele Spalten - volle Breite statt der schmalen Inhaltsspalte.
|
|
$containerWide = true;
|
|
include __DIR__ . '/../includes/header.php';
|
|
?>
|
|
<div class="panel">
|
|
<h1>Benutzerverwaltung</h1>
|
|
<p class="text-muted">
|
|
Wer sich zum ersten Mal über Discord anmeldet, bekommt automatisch ein Konto, das erst
|
|
freigeschaltet werden muss. Berechtigungsgruppen mit verknüpfter Discord-Rolle werden
|
|
automatisch vergeben und entzogen.
|
|
</p>
|
|
|
|
<?php // Beide Knoepfe gleich breit untereinander, die Erklaerung zum Abgleich daneben ?>
|
|
<div class="user-admin-actions">
|
|
<?php if ($canCreate): ?>
|
|
<a class="button" href="/admin/user_form.php">Neuen Benutzer anlegen</a>
|
|
<?php endif; ?>
|
|
<?php if ($canEdit): ?>
|
|
<form class="discord-sync-form" method="post" action="/admin/discord_sync_action.php">
|
|
<?= csrf_field() ?>
|
|
<button type="submit" class="button discord-connect-button"><?= discord_logo(16) ?> Jetzt mit Discord abgleichen</button>
|
|
<span class="text-muted">Gleicht Server-Mitgliedschaft, Rollen und Klassen aller Konten sofort ab. Automatisch passiert das bei jeder Anmeldung und danach alle 5 Minuten, solange jemand eingeloggt ist.</span>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php if ($canEdit): ?>
|
|
|
|
<form class="settings-toggle" method="post" action="/admin/settings_action.php">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="setting" value="discord_unlink_allowed">
|
|
<label>
|
|
<input type="checkbox" name="value" value="1" <?= discord_unlink_allowed() ? 'checked' : '' ?> onchange="this.form.submit()">
|
|
Mitglieder dürfen ihre Discord-Verknüpfung im Profil lösen
|
|
</label>
|
|
<noscript><button type="submit" class="button-secondary button-small">Speichern</button></noscript>
|
|
</form>
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
$statusCounts = array_count_values(array_column($users, 'status'));
|
|
$adminCount = count(array_filter($users, static fn ($u) => !empty($u['is_admin']) || is_developer($u)));
|
|
?>
|
|
<div class="list-toolbar" id="users-toolbar">
|
|
<label class="search-field">
|
|
<?= icon('search') ?>
|
|
<input type="search" id="users-search" placeholder="Benutzername, Anzeigename, Discord oder Gruppe suchen …" aria-label="Benutzer durchsuchen">
|
|
</label>
|
|
<div class="list-toolbar-row">
|
|
<div class="members-chips" data-filter="status" role="group" aria-label="Nach Status filtern">
|
|
<button type="button" class="members-chip active" data-value="">Alle <span class="chip-count"><?= count($users) ?></span></button>
|
|
<?php if (!empty($statusCounts['pending'])): ?>
|
|
<button type="button" class="members-chip" data-value="pending">Wartet auf Freischaltung <span class="chip-count"><?= $statusCounts['pending'] ?></span></button>
|
|
<?php endif; ?>
|
|
<button type="button" class="members-chip" data-value="active">Aktiv <span class="chip-count"><?= $statusCounts['active'] ?? 0 ?></span></button>
|
|
<?php if (!empty($statusCounts['disabled'])): ?>
|
|
<button type="button" class="members-chip" data-value="disabled">Deaktiviert <span class="chip-count"><?= $statusCounts['disabled'] ?></span></button>
|
|
<?php endif; ?>
|
|
<?php if ($adminCount > 0): ?>
|
|
<button type="button" class="members-chip" data-value="admin">Administratoren <span class="chip-count"><?= $adminCount ?></span></button>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="list-toolbar-meta">
|
|
<span class="members-filter-label"><?= icon('sort') ?> Sortieren</span>
|
|
<div class="members-segment" data-filter="sort" role="group" aria-label="Sortieren">
|
|
<button type="button" data-value="rank" class="active">Rang</button>
|
|
<button type="button" data-value="name">Name</button>
|
|
<button type="button" data-value="login">Letzter Login</button>
|
|
<button type="button" data-value="created">Neueste</button>
|
|
</div>
|
|
<span class="list-search-count text-muted" id="users-count"></span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="table-scroll">
|
|
<table class="table-actions" id="users-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Benutzername</th>
|
|
<th>Anzeigename</th>
|
|
<th>Discord</th>
|
|
<th>Berechtigungsgruppen</th>
|
|
<th>Status</th>
|
|
<th>Letzter Login</th>
|
|
<?php if ($canEdit || $canDelete): ?><th>Aktionen</th><?php endif; ?>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php $rowIndex = 0; ?>
|
|
<?php foreach ($users as $u): ?>
|
|
<?php
|
|
[$statusLabel, $statusClass] = $statusLabels[$u['status']] ?? [$u['status'], ''];
|
|
// Administratoren bearbeiten/loeschen nur mit users.admin.
|
|
$protectedAdmin = !empty($u['is_admin']) && !$canManageAdmins;
|
|
// Entwickler-Konten bearbeiten/loeschen nur andere Entwickler.
|
|
$isDevRow = is_developer($u);
|
|
if ($isDevRow && !is_developer($currentUser)) {
|
|
$protectedAdmin = true;
|
|
}
|
|
?>
|
|
<tr<?= $u['status'] === 'pending' ? ' class="row-pending"' : '' ?>
|
|
data-rank="<?= (int) $rowIndex++ ?>"
|
|
data-name="<?= e(mb_strtolower($u['display_name'] !== '' ? $u['display_name'] : $u['username'])) ?>"
|
|
data-search="<?= e(mb_strtolower($u['username'] . ' ' . $u['display_name'] . ' ' . ($u['discord_username'] ?? '') . ' ' . ($u['role_names'] ?? ''))) ?>"
|
|
data-status="<?= e($u['status']) ?>"
|
|
data-admin="<?= !empty($u['is_admin']) || $isDevRow ? '1' : '0' ?>"
|
|
data-login="<?= e((string) ($u['last_login'] ?? '')) ?>"
|
|
data-created="<?= e((string) $u['created_at']) ?>">
|
|
<td><?= e($u['username']) ?></td>
|
|
<td><?= e($u['display_name']) ?></td>
|
|
<td>
|
|
<?php if (!empty($u['discord_id'])): ?>
|
|
<span class="discord-inline"><?= discord_logo(14) ?> <?= e((string) $u['discord_username']) ?></span>
|
|
<?php else: ?>
|
|
<span class="text-muted">-</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><?= e($u['role_names'] ?: '-') ?></td>
|
|
<td>
|
|
<div class="badge-group">
|
|
<?php if (!empty($u['deleted_at'])): ?>
|
|
<span class="badge badge-disabled" title="Am <?= e(date('d.m.Y', (int) strtotime((string) $u['deleted_at']))) ?> gelöscht - ohne Namen und Discord-ID">Gelöscht (unkenntlich)</span>
|
|
<?php else: ?>
|
|
<span class="badge <?= e($statusClass) ?>"><?= e($statusLabel) ?></span>
|
|
<?php endif; ?>
|
|
<?php if (!empty($u['deletion_scheduled_at']) && empty($u['deleted_at'])): ?>
|
|
<span class="badge badge-disabled" title="Vom Mitglied beantragt - Anmelden bricht die Löschung ab">Löschung am <?= e(date('d.m.', (int) strtotime((string) $u['deletion_scheduled_at']))) ?></span>
|
|
<?php endif; ?>
|
|
<?php if ($isDevRow): ?>
|
|
<span class="badge badge-developer" title="Entwickler der Website - hat immer alle Berechtigungen"><?= icon('code') ?> Entwickler</span>
|
|
<?php endif; ?>
|
|
<?php if (!empty($u['is_admin'])): ?>
|
|
<span class="badge badge-admin" title="Hat alle Berechtigungen"><?= icon('crown') ?> Administrator</span>
|
|
<?php endif; ?>
|
|
<?php if (empty($u['password_login'])): ?>
|
|
<span class="badge" title="Anmeldung nur über Discord möglich">Nur Discord</span>
|
|
<?php elseif ($u['must_change_password']): ?>
|
|
<span class="badge" title="Benutzer muss beim nächsten Login das Passwort ändern">Passwortänderung ausstehend</span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</td>
|
|
<td><?= e($u['last_login'] ?? 'nie') ?></td>
|
|
<?php if ($canEdit || $canDelete): ?>
|
|
<td>
|
|
<div class="actions">
|
|
<?php if ($canEdit && $u['status'] === 'pending'): ?>
|
|
<form class="inline-form" method="post" action="/admin/user_approve.php">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="id" value="<?= (int) $u['id'] ?>">
|
|
<button type="submit" class="button-success button-small">Freischalten</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
<?php if ($canEdit && !$protectedAdmin): ?>
|
|
<a class="icon-button" href="/admin/user_form.php?id=<?= (int) $u['id'] ?>" title="Bearbeiten" aria-label="Bearbeiten"><?= icon('edit') ?></a>
|
|
<?php endif; ?>
|
|
<?php if ($canExport && !$protectedAdmin): ?>
|
|
<a class="icon-button" href="/admin/user_export.php?id=<?= (int) $u['id'] ?>" title="Daten & Löschung (Auskunft, Download-Link, Konto löschen)" aria-label="Daten und Löschung"><?= icon('archive') ?></a>
|
|
<?php endif; ?>
|
|
<?php if ($canEdit && !$protectedAdmin && $u['status'] === 'active' && (int) $u['id'] !== (int) $currentUser['id']): ?>
|
|
<?php foreach (['logout' => ['log-out', 'Abmelden erzwingen (alle Sitzungen beenden)', 'Alle Sitzungen dieses Kontos beenden?'], 'lock' => ['lock', 'Sperren und überall abmelden', 'Dieses Konto sperren und überall abmelden?']] as $secAction => [$secIcon, $secTitle, $secQuestion]): ?>
|
|
<form class="inline-form" method="post" action="/admin/user_security.php"
|
|
data-confirm="<?= e($secQuestion) ?>" data-confirm-title="<?= e($secTitle) ?>" data-confirm-input="reason"
|
|
data-confirm-placeholder="Grund (optional, erscheint im Audit-Log)"<?= $secAction === 'lock' ? ' data-confirm-danger data-confirm-ok="Sperren"' : ' data-confirm-ok="Abmelden"' ?>>
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="id" value="<?= (int) $u['id'] ?>">
|
|
<input type="hidden" name="action" value="<?= $secAction ?>">
|
|
<input type="hidden" name="reason" value="">
|
|
<button type="submit" class="icon-button<?= $secAction === 'lock' ? ' icon-button-danger' : '' ?>" title="<?= e($secTitle) ?>" aria-label="<?= e($secTitle) ?>"><?= icon($secIcon) ?></button>
|
|
</form>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
<?php if ($canDelete && !$protectedAdmin && (int) $u['id'] !== (int) $currentUser['id']): ?>
|
|
<form class="inline-form" method="post" action="/admin/user_delete.php" data-confirm="Diesen Benutzer wirklich löschen?" data-confirm-title="Benutzer löschen" data-confirm-danger data-confirm-ok="Löschen">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="id" value="<?= (int) $u['id'] ?>">
|
|
<button type="submit" class="icon-button icon-button-danger" title="Löschen" aria-label="Löschen"><?= icon('trash') ?></button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</td>
|
|
<?php endif; ?>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<p class="text-muted" id="users-empty" hidden>Kein Benutzer passt zu Suche und Filter.</p>
|
|
</div>
|
|
<script src="<?= e(asset_url('/assets/js/admin-users.js')) ?>"></script>
|
|
<?php include __DIR__ . '/../includes/footer.php'; ?>
|