feat: 简航 SimpleNav 个人网站导航系统(PHP + SQLite)
- 前台:搜索引擎切换+联想下拉、网格板块(常用/工具)、合集标签页 - 后台:初始化/登录、网站/板块/引擎增删改、上下移排序 - 添加网站自动抓取名称与图标(存储于服务器),支持自定义简称 - 一键全部更新(批量刷新图标+名称,保留自定义简称) - 搜索联想服务端代理(必应/百度/谷歌/搜狗/360/DuckDuckGo) - 零依赖:原生 CSS/JS,PDO SQLite
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* 简航 SimpleNav —— 管理员登录 / 首次初始化
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/functions.php';
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
$hasAdmin = (int)db()->query('SELECT COUNT(*) FROM users')->fetchColumn() > 0;
|
||||
$err = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$u = trim((string)($_POST['username'] ?? ''));
|
||||
$p = (string)($_POST['password'] ?? '');
|
||||
if ($u === '' || $p === '') {
|
||||
$err = '请输入用户名和密码';
|
||||
} elseif (mb_strlen($p) < 4) {
|
||||
$err = '密码至少 4 位';
|
||||
} elseif (!$hasAdmin) {
|
||||
// 首次创建管理员
|
||||
$st = db()->prepare('INSERT INTO users (username, password_hash, created_at) VALUES (?,?,?)');
|
||||
$st->execute([$u, password_hash($p, PASSWORD_DEFAULT), date('Y-m-d H:i:s')]);
|
||||
$_SESSION['uid'] = (int)db()->lastInsertId();
|
||||
header('Location: ' . url('admin/'));
|
||||
exit;
|
||||
} else {
|
||||
// 登录校验
|
||||
$st = db()->prepare('SELECT * FROM users WHERE username=? LIMIT 1');
|
||||
$st->execute([$u]);
|
||||
$row = $st->fetch();
|
||||
if ($row && password_verify($p, $row['password_hash'])) {
|
||||
$_SESSION['uid'] = (int)$row['id'];
|
||||
header('Location: ' . url('admin/'));
|
||||
exit;
|
||||
}
|
||||
$err = '用户名或密码错误';
|
||||
}
|
||||
}
|
||||
$title = $hasAdmin ? '登录' : '初始化管理员';
|
||||
?><!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= e($title) ?> · <?= e(site_name()) ?></title>
|
||||
<link rel="stylesheet" href="<?= e(url('assets/css/style.css')) ?>">
|
||||
<link rel="stylesheet" href="<?= e(url('assets/css/admin.css')) ?>">
|
||||
</head>
|
||||
<body class="admin">
|
||||
<div class="login-wrap">
|
||||
<form class="login-card" method="post" action="">
|
||||
<img class="login-logo" src="<?= e(url('assets/img/logo.svg')) ?>" alt="" onerror="this.style.display='none'">
|
||||
<h1><?= e(site_name()) ?></h1>
|
||||
<p class="sub"><?= $hasAdmin ? '管理员登录' : '首次使用,请创建管理员账号' ?></p>
|
||||
<?php if ($err): ?><div class="alert"><?= e($err) ?></div><?php endif; ?>
|
||||
<input type="text" name="username" placeholder="用户名" autocomplete="username" required>
|
||||
<input type="password" name="password" placeholder="密码" autocomplete="<?= $hasAdmin ? 'current-password' : 'new-password' ?>" required>
|
||||
<button type="submit" class="btn primary block"><?= $hasAdmin ? '登录' : '创建并进入' ?></button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user