65 lines
2.9 KiB
PHP
65 lines
2.9 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/auth_layout.php';
|
|
|
|
// 已登录直接跳走,避免重复登录
|
|
$user = current_user($conn);
|
|
if ($user) {
|
|
header($user['is_admin'] ? 'Location: admin.php' : 'Location: gallery.php');
|
|
exit;
|
|
}
|
|
|
|
$error = '';
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$username = trim($_POST['username'] ?? '');
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
$stmt = $conn->prepare("SELECT user_id, username, password, active, is_admin FROM photo_users WHERE username = ?");
|
|
$stmt->bind_param("s", $username);
|
|
$stmt->execute();
|
|
$row = $stmt->get_result()->fetch_assoc();
|
|
$stmt->close();
|
|
|
|
if (!$row) {
|
|
$error = '用户名或密码错误。';
|
|
} elseif ((int)$row['active'] === 0) {
|
|
$error = '账号已被禁用,请联系管理员。';
|
|
} elseif (!password_verify($password, $row['password'])) {
|
|
$error = '用户名或密码错误。';
|
|
} else {
|
|
session_regenerate_id(true);
|
|
$_SESSION['loggedin'] = true;
|
|
$_SESSION['user_id'] = (int)$row['user_id'];
|
|
$_SESSION['user_name'] = $row['username'];
|
|
$_SESSION['is_admin'] = (bool)$row['is_admin'];
|
|
start_login($conn, (int)$row['user_id']);
|
|
}
|
|
}
|
|
|
|
render_auth_header('登录', '', 'square.php');
|
|
?>
|
|
<h2 class="auth__title">欢迎回来</h2>
|
|
<p class="auth__sub">登录后即可管理你的私人相册</p>
|
|
<?php if ($f = flash_take()): ?>
|
|
<div class="alert alert--success"><?php echo icon('check'); ?><span><?php echo h($f['msg']); ?></span></div>
|
|
<?php endif; ?>
|
|
<?php if ($error): ?>
|
|
<div class="alert alert--danger"><?php echo icon('warn'); ?><span><?php echo h($error); ?></span></div>
|
|
<?php endif; ?>
|
|
<form method="post" autocomplete="on">
|
|
<div class="field">
|
|
<label class="label" for="username">用户名</label>
|
|
<input class="input" type="text" id="username" name="username" autocomplete="username" placeholder="输入用户名" required autofocus>
|
|
</div>
|
|
<div class="field">
|
|
<label class="label" for="password">密码</label>
|
|
<div class="input-group">
|
|
<input class="input" type="password" id="password" name="password" autocomplete="current-password" placeholder="输入密码" required>
|
|
<button type="button" class="btn btn--ghost btn--icon" data-toggle-password="password" aria-label="显示密码"><?php echo icon('eye'); ?></button>
|
|
</div>
|
|
</div>
|
|
<button type="submit" class="btn btn--primary btn--lg btn--block">登录</button>
|
|
</form>
|
|
<p class="auth__foot">还没有账号?<a href="register.php">使用邀请码注册</a></p>
|
|
<p class="auth__foot" style="margin-top:.5rem"><a href="square.php"><?php echo icon('globe', 14); ?> 先逛逛照片广场(公开)</a></p>
|
|
<?php render_auth_footer();
|