279 lines
9.1 KiB
HTML
279 lines
9.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Benutzerverwaltung</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
background: #111;
|
|
color: #eee;
|
|
font-family: Arial, sans-serif;
|
|
padding: 20px;
|
|
}
|
|
h1 { margin-top: 0; }
|
|
a.back { color: #6fbf73; text-decoration: none; font-size: 14px; }
|
|
a.back:hover { text-decoration: underline; }
|
|
|
|
.panel {
|
|
background: #1a1a1a;
|
|
border: 1px solid #333;
|
|
border-radius: 8px;
|
|
padding: 16px;
|
|
margin-top: 16px;
|
|
}
|
|
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-top: 10px;
|
|
}
|
|
th, td {
|
|
text-align: left;
|
|
padding: 8px;
|
|
border-bottom: 1px solid #333;
|
|
font-size: 14px;
|
|
}
|
|
th { color: #aaa; font-weight: normal; }
|
|
|
|
button {
|
|
border: none;
|
|
color: white;
|
|
padding: 5px 10px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 13px;
|
|
margin-right: 4px;
|
|
}
|
|
button.approve { background: #2c7a3d; }
|
|
button.revoke { background: #a83232; }
|
|
button.admin-on { background: #4942ae; }
|
|
button.admin-off { background: #333; }
|
|
button:hover { opacity: 0.85; }
|
|
|
|
.badge {
|
|
display: inline-block;
|
|
border-radius: 4px;
|
|
padding: 2px 8px;
|
|
font-size: 12px;
|
|
}
|
|
.badge.pending { background: #6b5b1a; color: #ffd76b; }
|
|
.badge.approved { background: #1a4d2a; color: #6fbf73; }
|
|
.badge.admin { background: #2f2a5e; color: #b3a6ff; margin-left: 4px; }
|
|
|
|
.msg { font-size: 13px; color: #6fbf73; min-height: 18px; margin-top: 8px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<a class="back" href="/index.html">← zurück zur Startseite</a>
|
|
<h1>👥 Benutzerverwaltung</h1>
|
|
|
|
<div class="panel">
|
|
<div class="msg" id="userMsg"></div>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Username</th>
|
|
<th>Status</th>
|
|
<th>Bargeld</th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="usersTableBody"></tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<script>
|
|
const token = localStorage.getItem("token");
|
|
// Voll-Admin ODER passende Gruppen-Berechtigung reicht jetzt aus - der
|
|
// Server prüft das bei jedem Aufruf ohnehin final ab (siehe requireAdmin);
|
|
// hier reicht ein simpler Login-Check, authFetch() fängt fehlende Rechte
|
|
// beim ersten echten API-Aufruf sauber ab (Meldung + Weiterleitung)
|
|
let isAdmin = localStorage.getItem("isAdmin") === "true";
|
|
|
|
if (!token) {
|
|
alert("Bitte zuerst einloggen.");
|
|
location.href = "/index.html";
|
|
}
|
|
|
|
async function authFetch(url, options = {}) {
|
|
options.headers = { ...(options.headers || {}), "Authorization": "Bearer " + token };
|
|
const res = await fetch(url, options);
|
|
if (res.status === 401 || res.status === 403) {
|
|
alert("Sitzung abgelaufen oder kein Admin-Zugriff. Bitte erneut einloggen.");
|
|
location.href = "/index.html";
|
|
throw new Error("Nicht autorisiert");
|
|
}
|
|
return res;
|
|
}
|
|
|
|
let allUsers = [];
|
|
|
|
async function loadUsers() {
|
|
const res = await authFetch("/api/admin/players");
|
|
const data = await res.json();
|
|
allUsers = data.players || [];
|
|
renderUsers();
|
|
}
|
|
|
|
function renderUsers() {
|
|
const body = document.getElementById("usersTableBody");
|
|
body.innerHTML = "";
|
|
|
|
allUsers.forEach(u => {
|
|
const tr = document.createElement("tr");
|
|
|
|
const statusBadge = u.approved
|
|
? `<span class="badge approved">Freigeschaltet</span>`
|
|
: `<span class="badge pending">Wartet auf Freischaltung</span>`;
|
|
const adminBadge = u.is_admin ? `<span class="badge admin">Admin</span>` : "";
|
|
const betaBadge = u.is_beta_tester ? `<span class="badge" style="background:#3a1a5a; color:#c9a8ff;">Beta-Tester</span>` : "";
|
|
const bannedBadge = u.banned ? `<span class="badge" style="background:#5a1a1a; color:#ff8080;">Gesperrt</span>` : "";
|
|
const isMuted = u.muted_until && new Date(u.muted_until).getTime() > Date.now();
|
|
const mutedBadge = isMuted ? `<span class="badge" style="background:#5a4a1a; color:#ffd580;">Stumm</span>` : "";
|
|
|
|
tr.innerHTML = `
|
|
<td>${u.username}</td>
|
|
<td>
|
|
${statusBadge}${adminBadge}${betaBadge}${bannedBadge}${mutedBadge}
|
|
${!u.approved && u.application_text ? `<div style="color:#999; font-size:12px; margin-top:6px; max-width:320px; white-space:pre-wrap;">"${escapeHtml(u.application_text)}"</div>` : ""}
|
|
</td>
|
|
<td>${u.money}$</td>
|
|
<td>
|
|
${u.approved
|
|
? `<button class="revoke" onclick="revokeUser(${u.id})">Sperren</button>`
|
|
: `<button class="approve" onclick="approveUser(${u.id})">Freischalten</button>
|
|
<button class="admin-off" onclick="rejectUser(${u.id})">Ablehnen</button>`}
|
|
<button class="${u.is_admin ? 'admin-off' : 'admin-on'}" onclick="toggleAdmin(${u.id}, ${!u.is_admin})">
|
|
${u.is_admin ? "Admin entziehen" : "Zum Admin machen"}
|
|
</button>
|
|
<button class="${u.is_beta_tester ? 'admin-off' : 'admin-on'}" onclick="toggleBetaTester(${u.id}, ${!u.is_beta_tester})">
|
|
${u.is_beta_tester ? "Beta-Zugang entziehen" : "Beta-Zugang geben"}
|
|
</button>
|
|
<button class="${u.banned ? 'admin-on' : 'admin-off'}" onclick="toggleBan(${u.id}, ${!u.banned})">
|
|
${u.banned ? "Entsperren" : "Bannen"}
|
|
</button>
|
|
${isMuted
|
|
? `<button class="admin-on" onclick="muteUser(${u.id}, 0)">Entstummen</button>`
|
|
: `<button class="admin-off" onclick="muteUser(${u.id}, null)">Stummschalten</button>`}
|
|
</td>
|
|
`;
|
|
body.appendChild(tr);
|
|
});
|
|
}
|
|
|
|
async function toggleBan(id, banned) {
|
|
const res = await authFetch(`/api/admin/players/${id}/ban`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ banned })
|
|
});
|
|
const data = await res.json();
|
|
if (data.ok) loadUsers();
|
|
else alert("Fehler beim Ändern des Bann-Status.");
|
|
}
|
|
|
|
async function muteUser(id, minutes) {
|
|
if (minutes === null) {
|
|
const input = prompt("Für wie viele Minuten stummschalten?", "30");
|
|
if (!input) return;
|
|
minutes = Number(input);
|
|
if (!minutes || minutes <= 0) return;
|
|
}
|
|
|
|
const res = await authFetch(`/api/admin/players/${id}/mute`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ minutes })
|
|
});
|
|
const data = await res.json();
|
|
if (data.ok) loadUsers();
|
|
else alert("Fehler beim Stummschalten.");
|
|
}
|
|
|
|
async function approveUser(id) {
|
|
const res = await authFetch(`/api/admin/players/${id}/approve`, { method: "POST" });
|
|
const data = await res.json();
|
|
if (data.ok) {
|
|
showMsg("Benutzer freigeschaltet.");
|
|
loadUsers();
|
|
} else {
|
|
showMsg("Fehler beim Freischalten.", true);
|
|
}
|
|
}
|
|
|
|
async function rejectUser(id) {
|
|
if (!confirm("Diese Bewerbung wirklich ablehnen? Der Account wird komplett gelöscht.")) return;
|
|
|
|
const res = await authFetch(`/api/admin/players/${id}/reject`, { method: "POST" });
|
|
const data = await res.json();
|
|
if (data.ok) {
|
|
showMsg("Bewerbung abgelehnt.");
|
|
loadUsers();
|
|
} else {
|
|
showMsg(data.error || "Fehler beim Ablehnen.", true);
|
|
}
|
|
}
|
|
|
|
function escapeHtml(text) {
|
|
const div = document.createElement("div");
|
|
div.textContent = text == null ? "" : String(text);
|
|
return div.innerHTML;
|
|
}
|
|
|
|
async function revokeUser(id) {
|
|
if (!confirm("Diesen Benutzer wirklich sperren? Eine aktive Verbindung wird getrennt.")) return;
|
|
|
|
const res = await authFetch(`/api/admin/players/${id}/revoke`, { method: "POST" });
|
|
const data = await res.json();
|
|
if (data.ok) {
|
|
showMsg("Benutzer gesperrt.");
|
|
loadUsers();
|
|
} else {
|
|
showMsg("Fehler beim Sperren.", true);
|
|
}
|
|
}
|
|
|
|
async function toggleAdmin(id, makeAdmin) {
|
|
const res = await authFetch(`/api/admin/players/${id}/set_admin`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ isAdmin: makeAdmin })
|
|
});
|
|
const data = await res.json();
|
|
if (data.ok) {
|
|
showMsg(makeAdmin ? "Admin-Rechte vergeben." : "Admin-Rechte entzogen.");
|
|
loadUsers();
|
|
} else {
|
|
showMsg("Fehler.", true);
|
|
}
|
|
}
|
|
|
|
async function toggleBetaTester(id, makeBetaTester) {
|
|
const res = await authFetch(`/api/admin/players/${id}/set_beta_tester`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ isBetaTester: makeBetaTester })
|
|
});
|
|
const data = await res.json();
|
|
if (data.ok) {
|
|
showMsg(makeBetaTester ? "Beta-Zugang vergeben." : "Beta-Zugang entzogen.");
|
|
loadUsers();
|
|
} else {
|
|
showMsg("Fehler.", true);
|
|
}
|
|
}
|
|
|
|
function showMsg(text, isError) {
|
|
const el = document.getElementById("userMsg");
|
|
el.style.color = isError ? "#e06c6c" : "#6fbf73";
|
|
el.textContent = text;
|
|
setTimeout(() => { el.textContent = ""; }, 4000);
|
|
}
|
|
|
|
loadUsers();
|
|
</script>
|
|
|
|
</body>
|
|
</html> |