38451-vm/admin/login.php
Flatlogic Bot 301a100f16 2/19
2026-02-19 03:14:52 +00:00

132 lines
4.3 KiB
PHP

<?php
require_once __DIR__ . '/../db/config.php';
require_once __DIR__ . '/../includes/lang.php';
if (session_status() === PHP_SESSION_NONE) session_start();
// If already logged in as admin, redirect to dashboard
if (isset($_SESSION['admin_id'])) {
header('Location: /admin/index.php');
exit;
}
$site_logo = '/assets/images/logo.png';
$site_favicon = '';
$site_name = 'Byro Admin';
try {
$stmt = db()->prepare("SELECT setting_value FROM system_settings WHERE setting_key = 'site_logo'");
$stmt->execute();
$val = $stmt->fetchColumn();
if ($val) $site_logo = $val;
$stmt = db()->prepare("SELECT setting_value FROM system_settings WHERE setting_key = 'site_favicon'");
$stmt->execute();
$val = $stmt->fetchColumn();
$site_favicon = $val ?: $site_logo;
$stmt = db()->prepare("SELECT setting_value FROM system_settings WHERE setting_key = 'site_name'");
$stmt->execute();
$name = $stmt->fetchColumn();
if ($name) $site_name = $name . ' Admin';
} catch (Exception $e) {}
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($username) || empty($password)) {
$error = '请输入账号和密码';
} else {
$stmt = db()->prepare("SELECT * FROM admins WHERE username = ?");
$stmt->execute([$username]);
$admin = $stmt->fetch();
if ($admin && password_verify($password, $admin['password_hash'])) {
$_SESSION['admin_id'] = $admin['id'];
$_SESSION['admin_username'] = $admin['username'];
$_SESSION['admin_role'] = $admin['role'];
header('Location: /admin/index.php');
exit;
} else {
$error = '管理员账号或密码错误';
}
}
}
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>管理员登录 - <?= $site_name ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
<?php if ($site_favicon): ?>
<link rel="icon" href="<?= $site_favicon ?>">
<?php endif; ?>
<style>
body {
background: #f4f7f6;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
font-family: 'PingFang SC', sans-serif;
}
.login-card {
width: 100%;
max-width: 400px;
background: #fff;
padding: 40px;
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0,0,0,0.05);
}
.logo {
text-align: center;
margin-bottom: 30px;
color: #0062ff;
font-size: 24px;
font-weight: bold;
}
.btn-primary {
background: #0062ff;
border: none;
padding: 12px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="login-card">
<div class="logo">
<?php if ($site_logo): ?>
<img src="<?= $site_logo ?>" height="40" class="mb-2 d-block mx-auto">
<?php else: ?>
<i class="bi bi-shield-lock-fill me-2"></i>
<?php endif; ?>
<div>后台管理系统</div>
</div>
<?php if ($error): ?>
<div class="alert alert-danger small py-2 px-3 mb-4">
<i class="bi bi-exclamation-circle me-2"></i><?= $error ?>
</div>
<?php endif; ?>
<form method="POST">
<div class="mb-3">
<label class="form-label small text-muted">管理员账号</label>
<input type="text" name="username" class="form-control" required>
</div>
<div class="mb-4">
<label class="form-label small text-muted">登录密码</label>
<input type="password" name="password" class="form-control" required>
</div>
<button type="submit" class="btn btn-primary w-100 rounded-pill">进入后台</button>
</form>
</div>
</body>
</html>