feat: 实现 Admin 首次初始化与网页登录 (#50)

This commit is contained in:
chengma
2026-08-09 13:36:41 +08:00
parent 1064ffed59
commit 0a7db404a1
17 changed files with 1140 additions and 12 deletions
+31
View File
@@ -0,0 +1,31 @@
{{define "auth/login"}}<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{.Title}} · 采集采购管理端</title>
<link rel="stylesheet" href="/static/css/app.css">
</head>
<body class="auth-page">
<main class="auth-card">
<h1>登录 Admin</h1>
<p class="hint">登录后进入采集采购管理端。</p>
{{if .Message}}<p class="{{if eq .Message "用户名或密码错误"}}missing{{else}}hint{{end}}" role="status">{{.Message}}</p>{{end}}
<form method="post" action="/login">
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
<input type="hidden" name="next" value="{{.Next}}">
<div class="field">
<label for="login-username">用户名</label>
<input id="login-username" type="text" name="username" value="{{.Username}}"
maxlength="64" required autocomplete="username" autofocus>
</div>
<div class="field">
<label for="login-password">密码</label>
<input id="login-password" type="password" name="password" maxlength="72"
required autocomplete="current-password">
</div>
<button type="submit" class="primary auth-submit">登录</button>
</form>
</main>
</body>
</html>{{end}}
+36
View File
@@ -0,0 +1,36 @@
{{define "auth/setup"}}<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{.Title}} · 采集采购管理端</title>
<link rel="stylesheet" href="/static/css/app.css">
</head>
<body class="auth-page">
<main class="auth-card">
<h1>初始化管理员</h1>
<p class="hint">首次使用需要创建管理员。系统没有固定默认密码,此入口完成后永久关闭。</p>
{{if .Message}}<p class="missing" role="alert">{{.Message}}</p>{{end}}
<form method="post" action="/setup">
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
<div class="field">
<label for="setup-username">用户名</label>
<input id="setup-username" type="text" name="username" value="{{.Username}}"
maxlength="64" required autocomplete="username" autofocus>
</div>
<div class="field">
<label for="setup-password">密码</label>
<input id="setup-password" type="password" name="password" minlength="8"
maxlength="72" required autocomplete="new-password">
<small>至少 8 个字符;请使用只有你知道的密码。</small>
</div>
<div class="field">
<label for="setup-password-confirm">确认密码</label>
<input id="setup-password-confirm" type="password" name="password_confirm"
minlength="8" maxlength="72" required autocomplete="new-password">
</div>
<button type="submit" class="primary auth-submit">创建管理员</button>
</form>
</main>
</body>
</html>{{end}}
+7
View File
@@ -15,6 +15,13 @@
<a href="/syb" class="{{if eq .Active "syb"}}active{{end}}">顺运宝数据</a>
<a href="/tasks" class="{{if eq .Active "tasks"}}active{{end}}">采集采购</a>
<a href="/clients" class="{{if eq .Active "clients"}}active{{end}}">客户端列表</a>
{{if .CurrentUser}}
<span class="nav-user">{{.CurrentUser.Username}}</span>
<form class="nav-logout" method="post" action="/logout">
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
<button type="submit">退出登录</button>
</form>
{{end}}
</nav>
<main class="page">