280 lines
8.2 KiB
PHP
280 lines
8.2 KiB
PHP
|
<?php
|
|||
|
session_start();
|
|||
|
|
|||
|
require_once '../config/database.php';
|
|||
|
require_once '../includes/utils.php';
|
|||
|
|
|||
|
// 如果已登录,跳转到管理页面
|
|||
|
if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in']) {
|
|||
|
header('Location: index.php');
|
|||
|
exit;
|
|||
|
}
|
|||
|
|
|||
|
$error = '';
|
|||
|
|
|||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
|
$username = trim($_POST['username'] ?? '');
|
|||
|
$password = $_POST['password'] ?? '';
|
|||
|
$captcha = $_POST['captcha'] ?? '';
|
|||
|
|
|||
|
if (empty($username) || empty($password) || empty($captcha)) {
|
|||
|
$error = '请填写完整信息';
|
|||
|
} elseif (!Utils::verifyCaptcha($captcha)) {
|
|||
|
$error = '验证码错误';
|
|||
|
} else {
|
|||
|
$database = new Database();
|
|||
|
$db = $database->getConnection();
|
|||
|
|
|||
|
$stmt = $db->prepare("SELECT id, username, password FROM admins WHERE username = ?");
|
|||
|
$stmt->execute([$username]);
|
|||
|
$admin = $stmt->fetch();
|
|||
|
|
|||
|
if ($admin && password_verify($password, $admin['password'])) {
|
|||
|
$_SESSION['admin_logged_in'] = true;
|
|||
|
$_SESSION['admin_id'] = $admin['id'];
|
|||
|
$_SESSION['admin_username'] = $admin['username'];
|
|||
|
header('Location: index.php');
|
|||
|
exit;
|
|||
|
} else {
|
|||
|
$error = '用户名或密码错误';
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
?>
|
|||
|
|
|||
|
<!DOCTYPE html>
|
|||
|
<html lang="zh-CN">
|
|||
|
<head>
|
|||
|
<meta charset="UTF-8">
|
|||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|||
|
<title>管理后台登录</title>
|
|||
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
|||
|
<style>
|
|||
|
* {
|
|||
|
margin: 0;
|
|||
|
padding: 0;
|
|||
|
box-sizing: border-box;
|
|||
|
}
|
|||
|
|
|||
|
body {
|
|||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|||
|
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
|
|||
|
min-height: 100vh;
|
|||
|
display: flex;
|
|||
|
align-items: center;
|
|||
|
justify-content: center;
|
|||
|
padding: 20px;
|
|||
|
}
|
|||
|
|
|||
|
.login-container {
|
|||
|
background: rgba(255, 255, 255, 0.95);
|
|||
|
border-radius: 20px;
|
|||
|
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
|
|||
|
overflow: hidden;
|
|||
|
width: 100%;
|
|||
|
max-width: 400px;
|
|||
|
backdrop-filter: blur(10px);
|
|||
|
}
|
|||
|
|
|||
|
.login-header {
|
|||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|||
|
color: white;
|
|||
|
padding: 40px 30px;
|
|||
|
text-align: center;
|
|||
|
}
|
|||
|
|
|||
|
.login-header h1 {
|
|||
|
font-size: 1.8rem;
|
|||
|
font-weight: 700;
|
|||
|
margin-bottom: 8px;
|
|||
|
}
|
|||
|
|
|||
|
.login-header p {
|
|||
|
opacity: 0.9;
|
|||
|
font-size: 0.9rem;
|
|||
|
}
|
|||
|
|
|||
|
.login-form {
|
|||
|
padding: 40px 30px;
|
|||
|
}
|
|||
|
|
|||
|
.form-group {
|
|||
|
margin-bottom: 25px;
|
|||
|
}
|
|||
|
|
|||
|
.form-group label {
|
|||
|
display: block;
|
|||
|
margin-bottom: 8px;
|
|||
|
font-weight: 600;
|
|||
|
color: #374151;
|
|||
|
font-size: 14px;
|
|||
|
}
|
|||
|
|
|||
|
.form-group input {
|
|||
|
width: 100%;
|
|||
|
padding: 12px 16px;
|
|||
|
border: 2px solid #e5e7eb;
|
|||
|
border-radius: 10px;
|
|||
|
font-size: 16px;
|
|||
|
transition: all 0.3s ease;
|
|||
|
background: #fafafa;
|
|||
|
}
|
|||
|
|
|||
|
.form-group input:focus {
|
|||
|
outline: none;
|
|||
|
border-color: #667eea;
|
|||
|
background: white;
|
|||
|
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
|||
|
}
|
|||
|
|
|||
|
.captcha-group {
|
|||
|
display: flex;
|
|||
|
gap: 10px;
|
|||
|
align-items: end;
|
|||
|
}
|
|||
|
|
|||
|
.captcha-group input {
|
|||
|
flex: 1;
|
|||
|
}
|
|||
|
|
|||
|
.captcha-image {
|
|||
|
border: 2px solid #e5e7eb;
|
|||
|
border-radius: 8px;
|
|||
|
cursor: pointer;
|
|||
|
transition: all 0.3s ease;
|
|||
|
}
|
|||
|
|
|||
|
.captcha-image:hover {
|
|||
|
border-color: #667eea;
|
|||
|
}
|
|||
|
|
|||
|
.error-message {
|
|||
|
background: #fee2e2;
|
|||
|
color: #991b1b;
|
|||
|
padding: 12px 16px;
|
|||
|
border-radius: 8px;
|
|||
|
margin-bottom: 20px;
|
|||
|
font-size: 14px;
|
|||
|
border: 1px solid #fecaca;
|
|||
|
}
|
|||
|
|
|||
|
.login-btn {
|
|||
|
width: 100%;
|
|||
|
padding: 14px;
|
|||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|||
|
color: white;
|
|||
|
border: none;
|
|||
|
border-radius: 10px;
|
|||
|
font-size: 16px;
|
|||
|
font-weight: 600;
|
|||
|
cursor: pointer;
|
|||
|
transition: all 0.3s ease;
|
|||
|
display: flex;
|
|||
|
align-items: center;
|
|||
|
justify-content: center;
|
|||
|
gap: 8px;
|
|||
|
}
|
|||
|
|
|||
|
.login-btn:hover {
|
|||
|
transform: translateY(-2px);
|
|||
|
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
|
|||
|
}
|
|||
|
|
|||
|
.login-btn:active {
|
|||
|
transform: translateY(0);
|
|||
|
}
|
|||
|
|
|||
|
.default-account {
|
|||
|
margin-top: 20px;
|
|||
|
padding: 15px;
|
|||
|
background: #f0f9ff;
|
|||
|
border: 1px solid #bae6fd;
|
|||
|
border-radius: 8px;
|
|||
|
font-size: 13px;
|
|||
|
color: #0369a1;
|
|||
|
}
|
|||
|
|
|||
|
.default-account strong {
|
|||
|
display: block;
|
|||
|
margin-bottom: 5px;
|
|||
|
}
|
|||
|
|
|||
|
@media (max-width: 480px) {
|
|||
|
.login-container {
|
|||
|
margin: 10px;
|
|||
|
border-radius: 15px;
|
|||
|
}
|
|||
|
|
|||
|
.login-header {
|
|||
|
padding: 30px 20px;
|
|||
|
}
|
|||
|
|
|||
|
.login-form {
|
|||
|
padding: 30px 20px;
|
|||
|
}
|
|||
|
}
|
|||
|
</style>
|
|||
|
</head>
|
|||
|
<body>
|
|||
|
<div class="login-container">
|
|||
|
<div class="login-header">
|
|||
|
<h1><i class="fas fa-shield-alt"></i> 管理后台</h1>
|
|||
|
<p>内容投稿系统管理中心</p>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="login-form">
|
|||
|
<?php if ($error): ?>
|
|||
|
<div class="error-message">
|
|||
|
<i class="fas fa-exclamation-circle"></i> <?php echo htmlspecialchars($error); ?>
|
|||
|
</div>
|
|||
|
<?php endif; ?>
|
|||
|
|
|||
|
<form method="POST">
|
|||
|
<div class="form-group">
|
|||
|
<label for="username">用户名</label>
|
|||
|
<input type="text" id="username" name="username" required
|
|||
|
value="<?php echo htmlspecialchars($_POST['username'] ?? ''); ?>">
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="form-group">
|
|||
|
<label for="password">密码</label>
|
|||
|
<input type="password" id="password" name="password" required>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="form-group">
|
|||
|
<label for="captcha">验证码</label>
|
|||
|
<div class="captcha-group">
|
|||
|
<input type="text" id="captcha" name="captcha" required
|
|||
|
placeholder="请输入验证码" maxlength="4">
|
|||
|
<img src="captcha.php" alt="验证码" class="captcha-image"
|
|||
|
onclick="this.src='captcha.php?'+Math.random()"
|
|||
|
title="点击刷新验证码">
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<button type="submit" class="login-btn">
|
|||
|
<i class="fas fa-sign-in-alt"></i> 登录
|
|||
|
</button>
|
|||
|
</form>
|
|||
|
|
|||
|
<div class="default-account">
|
|||
|
<strong><i class="fas fa-info-circle"></i> 默认账户信息:</strong>
|
|||
|
用户名:admin<br>
|
|||
|
密码:admin
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<script>
|
|||
|
// 自动聚焦到用户名输入框
|
|||
|
document.getElementById('username').focus();
|
|||
|
|
|||
|
// 回车键提交表单
|
|||
|
document.addEventListener('keypress', function(e) {
|
|||
|
if (e.key === 'Enter') {
|
|||
|
document.querySelector('form').submit();
|
|||
|
}
|
|||
|
});
|
|||
|
</script>
|
|||
|
</body>
|
|||
|
</html>
|