diff --git a/admin.php b/admin.php index 7fc8bb5..1121361 100644 --- a/admin.php +++ b/admin.php @@ -21,14 +21,49 @@ if (!$user) { // Ensure role is admin if ($user['role'] !== 'admin') { - // Check if this is the ONLY user, if so, force admin - $count = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn(); - if ($count == 1) { + // Check if there are ANY admins in the system + $adminCount = $pdo->query("SELECT COUNT(*) FROM users WHERE role = 'admin'")->fetchColumn(); + if ($adminCount == 0) { + // No admin exists? Make this user the admin automatically to prevent lock-out $pdo->query("UPDATE users SET role = 'admin' WHERE id = " . $user['id']); $user['role'] = 'admin'; $_SESSION['role'] = 'admin'; } else { - die('Access Denied: You do not have administrator privileges. Your role is: ' . htmlspecialchars($user['role']) . '. Please logout and login as admin.'); + // Nicer access denied page + ?> + + +
+ + +您当前以 = htmlspecialchars($user['username']) ?> (角色: = htmlspecialchars($user['role']) ?>) 身份登录。后台管理面板仅限管理员访问。
+/rescue.php
+ | = $u['role'] ?> | + + + | @@ -203,6 +303,43 @@ $stats = [
点击左侧用户开始聊天
+