Guild members only need a username/password, and nothing in the app used email for anything (no notifications, no password reset). Drops the column from the schema, the login lookup, install.php, and the admin user list/form. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
62 lines
1.3 KiB
PHP
62 lines
1.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
function current_user(): ?array
|
|
{
|
|
static $user = null;
|
|
static $loaded = false;
|
|
|
|
if ($loaded) {
|
|
return $user;
|
|
}
|
|
$loaded = true;
|
|
|
|
if (empty($_SESSION['user_id'])) {
|
|
return null;
|
|
}
|
|
|
|
$stmt = db()->prepare('SELECT id, username, display_name, status FROM users WHERE id = ?');
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$row = $stmt->fetch();
|
|
|
|
if (!$row || $row['status'] !== 'active') {
|
|
// Benutzer wurde geloescht oder deaktiviert -> Session beenden.
|
|
session_destroy();
|
|
return null;
|
|
}
|
|
|
|
$user = $row;
|
|
return $user;
|
|
}
|
|
|
|
function require_login(): void
|
|
{
|
|
if (!current_user()) {
|
|
redirect('/login.php');
|
|
}
|
|
}
|
|
|
|
function attempt_login(string $username, string $password): bool
|
|
{
|
|
$stmt = db()->prepare('SELECT id, password_hash, status FROM users WHERE username = ?');
|
|
$stmt->execute([$username]);
|
|
$row = $stmt->fetch();
|
|
|
|
if (!$row || $row['status'] !== 'active' || !password_verify($password, $row['password_hash'])) {
|
|
return false;
|
|
}
|
|
|
|
session_regenerate_id(true);
|
|
$_SESSION['user_id'] = $row['id'];
|
|
|
|
$update = db()->prepare('UPDATE users SET last_login = NOW() WHERE id = ?');
|
|
$update->execute([$row['id']]);
|
|
|
|
return true;
|
|
}
|
|
|
|
function logout(): void
|
|
{
|
|
$_SESSION = [];
|
|
session_destroy();
|
|
}
|