商城
This commit is contained in:
parent
381227ab21
commit
a22b771da1
BIN
assets/pasted-20260208-123344-c6190c96.png
Normal file
BIN
assets/pasted-20260208-123344-c6190c96.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../db/config.php';
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
// Fetch site settings
|
||||
try {
|
||||
@ -100,10 +102,8 @@ $mobile_accent = $settings['mobile_accent_color'] ?? '#ff9900';
|
||||
0
|
||||
</span>
|
||||
</a>
|
||||
<?php if (isset($_SESSION['admin_logged_in'])): ?>
|
||||
<?php if (isset($_SESSION['user_id']) && $_SESSION['role'] === 'admin'): ?>
|
||||
<a href="admin/index.php" class="btn btn-sm btn-outline-dark">后台管理</a>
|
||||
<?php else: ?>
|
||||
<a href="login.php" class="btn btn-sm btn-outline-dark">登录</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -18,6 +18,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$_SESSION['role'] = $user['role'];
|
||||
|
||||
if ($user['role'] === 'admin') {
|
||||
$_SESSION['admin_logged_in'] = true;
|
||||
header("Location: admin/index.php");
|
||||
} else {
|
||||
header("Location: index.php");
|
||||
@ -59,16 +60,8 @@ require_once 'includes/header.php';
|
||||
<input type="password" name="password" class="form-control bg-black bg-opacity-50 border-secondary border-opacity-50 text-white p-3 rounded-3" placeholder="输入密码" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary btn-lg w-100 py-3 rounded-3 shadow mb-4">立即登录</button>
|
||||
<div class="text-center">
|
||||
<span class="text-muted small">还没有账号? <a href="register.php" class="text-primary text-decoration-none">立即注册</a></span>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="text-center mt-4">
|
||||
<div class="alert alert-info bg-info bg-opacity-10 border-0 text-info rounded-4 small py-2">
|
||||
<i class="bi bi-info-circle me-1"></i> 测试账号: admin / admin123
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
82
register.php
82
register.php
@ -1,82 +1,4 @@
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
session_start();
|
||||
$db = db();
|
||||
|
||||
$error = '';
|
||||
$success = '';
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
$confirm = $_POST['confirm_password'];
|
||||
$email = $_POST['email'];
|
||||
|
||||
if ($password !== $confirm) {
|
||||
$error = '两次输入的密码不一致';
|
||||
} else {
|
||||
$hashed = password_hash($password, PASSWORD_DEFAULT);
|
||||
try {
|
||||
$stmt = $db->prepare("INSERT INTO users (username, password, email, role) VALUES (?, ?, ?, 'user')");
|
||||
$stmt->execute([$username, $hashed, $email]);
|
||||
$success = '注册成功,请登录';
|
||||
} catch (PDOException $e) {
|
||||
$error = '用户名或邮箱已存在';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$page_title = '注册 - 豪软世界';
|
||||
require_once 'includes/header.php';
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
?>
|
||||
|
||||
<main class="py-5">
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-5">
|
||||
<div class="bg-dark bg-opacity-50 rounded-5 border border-secondary border-opacity-25 p-5 shadow-lg">
|
||||
<div class="text-center mb-5">
|
||||
<h2 class="text-white fw-bold">加入我们</h2>
|
||||
<p class="text-muted">开启您的软件选购之旅</p>
|
||||
</div>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-danger bg-danger bg-opacity-10 border-0 text-danger rounded-4 small">
|
||||
<?php echo $error; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($success): ?>
|
||||
<div class="alert alert-success bg-success bg-opacity-10 border-0 text-success rounded-4 small">
|
||||
<?php echo $success; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="POST">
|
||||
<div class="mb-4">
|
||||
<label class="form-label text-white small fw-bold">用户名</label>
|
||||
<input type="text" name="username" class="form-control bg-black bg-opacity-50 border-secondary border-opacity-50 text-white p-3 rounded-3" required>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="form-label text-white small fw-bold">电子邮箱</label>
|
||||
<input type="email" name="email" class="form-control bg-black bg-opacity-50 border-secondary border-opacity-50 text-white p-3 rounded-3" required>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="form-label text-white small fw-bold">设置密码</label>
|
||||
<input type="password" name="password" class="form-control bg-black bg-opacity-50 border-secondary border-opacity-50 text-white p-3 rounded-3" required>
|
||||
</div>
|
||||
<div class="mb-5">
|
||||
<label class="form-label text-white small fw-bold">确认密码</label>
|
||||
<input type="password" name="confirm_password" class="form-control bg-black bg-opacity-50 border-secondary border-opacity-50 text-white p-3 rounded-3" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary btn-lg w-100 py-3 rounded-3 shadow mb-4">立即注册</button>
|
||||
<div class="text-center">
|
||||
<span class="text-muted small">已有账号? <a href="login.php" class="text-primary text-decoration-none">立即登录</a></span>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<?php require_once 'includes/footer.php'; ?>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user