61 lines
2.3 KiB
PHP
61 lines
2.3 KiB
PHP
<?php
|
|
// 后台登录(仅管理员 is_admin=1 可进入)
|
|
session_start();
|
|
|
|
require_once __DIR__ . '/../includes/_install_redirect.php';
|
|
define('IN_APP', true);
|
|
require_once __DIR__ . '/../config.php';
|
|
require_once __DIR__ . '/../includes/db.php';
|
|
require_once __DIR__ . '/../includes/functions.php';
|
|
|
|
if (!empty($_SESSION['admin_id'])) {
|
|
header("HTTP/2 404 Not Found");
|
|
exit;
|
|
}
|
|
|
|
$err = '';
|
|
$cssVer = file_exists(__DIR__ . '/../assets/style.css') ? filemtime(__DIR__ . '/../assets/style.css') : time();
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
verifyCsrf();
|
|
$u = trim($_POST['username'] ?? '');
|
|
$pw = $_POST['password'] ?? '';
|
|
$stmt = db()->prepare('SELECT * FROM ' . tn('users') . ' WHERE username = ? AND role IN (\'admin\', \'cs\')');
|
|
$stmt->execute([$u]);
|
|
$row = $stmt->fetch();
|
|
if ($row && password_verify($pw, $row['password'])) {
|
|
$_SESSION['admin_id'] = $row['id'];
|
|
$_SESSION['admin_user'] = $row['username'];
|
|
unset($_SESSION['csrf']);
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
$err = '管理员账号或密码错误';
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="zh-CN" data-theme="<?= currentTheme() === 'dark' ? 'dark' : 'light' ?>">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>后台登录 - <?= h(SITE_NAME) ?></title>
|
|
<link rel="stylesheet" href="../assets/vendor/fontawesome/all.min.css">
|
|
<link rel="stylesheet" href="../assets/style.css?v=<?= $cssVer ?>">
|
|
</head>
|
|
<body>
|
|
<div class="admin-login">
|
|
<div class="auth-card">
|
|
<h2 class="al-title"><i class="fas fa-user-shield"></i> 后台登录</h2>
|
|
<p class="al-sub"><?= h(SITE_NAME) ?> 管理后台</p>
|
|
<?php if ($err): ?><p class="form-err"><?= h($err) ?></p><?php endif; ?>
|
|
<form method="post" action="" class="auth-form">
|
|
<?= csrfField() ?>
|
|
<label>管理员账号<input type="text" name="username" required></label>
|
|
<label>密码<input type="password" name="password" required></label>
|
|
<button type="submit" class="btn btn-primary" style="width:100%">登 录</button>
|
|
</form>
|
|
<a href="../index.php" class="al-back"><i class="fas fa-arrow-left"></i> 返回商城前台</a>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|