Files
jinniu-daikuan/app/auth.php
T
a05075735d HEL-327: apply frost-obsidian day/night theme across the live PHP UI.
Replace the old teal top-nav shell with the fusion sidebar layout, token CSS, and HEL-325 logos without changing business rules, APIs, or calculator formulas.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: multica-agent <github@multica.ai>
2026-09-01 09:26:15 +08:00

51 lines
1.0 KiB
PHP
Executable File

<?php
declare(strict_types=1);
require_once __DIR__ . '/db.php';
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
function currentUser(): ?array
{
if (empty($_SESSION['uid'])) {
return null;
}
$stmt = db()->prepare('SELECT id, username, role, created_at FROM users WHERE id = :id');
$stmt->execute([':id' => (int)$_SESSION['uid']]);
$u = $stmt->fetch();
return $u ?: null;
}
function isAdmin(): bool
{
$u = currentUser();
return $u && $u['role'] === 'admin';
}
function requireLogin(): void
{
if (!currentUser()) {
header('Location: index.php?action=login');
exit;
}
}
function requireAdmin(): void
{
requireLogin();
if (!isAdmin()) {
http_response_code(403);
$me = currentUser();
if ($me && function_exists('pageHeader') && function_exists('fusionRestrictedCard')) {
pageHeader($me);
fusionRestrictedCard();
pageFooter();
} else {
echo '需要管理员权限';
}
exit;
}
}