The login page leads with "Mit Discord einloggen"; username/password stays available below and can be allowed or refused per user. The Discord login asks for identify + guilds.members.read, so the site itself can check that the account is on the legion's server and read its roles - no bot token on the webspace. Unknown accounts get a new user in the new status "pending", Discord-only, who sees nothing but a "Freischaltung ausstehend" page and has no permissions until approved from the user list. Permission groups can be linked to a Discord role. Linked groups are granted and revoked from the member's roles at every Discord login and then every five minutes during a session, using the stored (refreshed) user token; leaving the server removes them and ends a Discord session. Manual groups are untouched, and several linked roles simply add up their groups. New columns are added automatically on first request (includes/schema.php), since the login page itself needs them; existing accounts keep password login. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
56 lines
1.8 KiB
PHP
56 lines
1.8 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/bootstrap.php';
|
|
|
|
if ($user = current_user()) {
|
|
redirect($user['status'] === 'pending' ? '/pending.php' : '/dashboard.php');
|
|
}
|
|
|
|
$error = null;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
verify_csrf();
|
|
|
|
$username = trim((string) ($_POST['username'] ?? ''));
|
|
$password = (string) ($_POST['password'] ?? '');
|
|
|
|
if ($username === '' || $password === '') {
|
|
$error = 'Bitte Benutzername und Passwort eingeben.';
|
|
} else {
|
|
$error = attempt_login($username, $password);
|
|
if ($error === '') {
|
|
redirect('/dashboard.php');
|
|
}
|
|
}
|
|
}
|
|
|
|
$pageTitle = 'Login';
|
|
include __DIR__ . '/includes/header.php';
|
|
?>
|
|
<div class="panel panel-narrow login-panel">
|
|
<h1>Login</h1>
|
|
<p class="text-muted">Melde dich mit deinem Discord-Account vom Legions-Server an.</p>
|
|
|
|
<a class="button discord-connect-button login-discord-button" href="/discord_login.php">
|
|
<?= discord_logo(22) ?> Mit Discord einloggen
|
|
</a>
|
|
|
|
<details class="login-password"<?= $error ? ' open' : '' ?>>
|
|
<summary>Mit Benutzername und Passwort anmelden</summary>
|
|
<?php if ($error): ?>
|
|
<div class="flash flash-error"><?= e($error) ?></div>
|
|
<?php endif; ?>
|
|
<form method="post" action="/login.php">
|
|
<?= csrf_field() ?>
|
|
<div>
|
|
<label for="username">Benutzername</label>
|
|
<input type="text" id="username" name="username" required value="<?= e($_POST['username'] ?? '') ?>">
|
|
</div>
|
|
<div>
|
|
<label for="password">Passwort</label>
|
|
<input type="password" id="password" name="password" required>
|
|
</div>
|
|
<button type="submit" class="button-secondary">Anmelden</button>
|
|
</form>
|
|
</details>
|
|
</div>
|
|
<?php include __DIR__ . '/includes/footer.php'; ?>
|