proofdb/app/view/admin/login.html
2026-05-08 00:05:51 +08:00

88 lines
3.0 KiB
HTML

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>管理员登录</title>
<link rel="stylesheet" href="/admin.css">
</head>
<body class="admin-login">
<main class="admin-login-layout page-shell-wide">
<section class="admin-login-intro panel">
<div>
<div class="eyebrow">Protected Access / v<?=htmlspecialchars($version)?></div>
<h1 class="admin-login-title">管理员<br />登录</h1>
<p class="lead admin-login-lead">登入 Proof DB 管理后台。</p>
</div>
<div class="admin-login-facts">
<div>
<div class="metric-label">身份鉴别</div>
<div class="admin-landing-meta-value">内部账号密码</div>
</div>
</div>
</section>
<section class="admin-login-form-shell panel-soft">
<div class="admin-login-form-head">
<p class="admin-landing-portal-title">进入维护面板</p>
<p class="admin-login-form-copy">请使用您的账号和密码进行登录</p>
</div>
<div id="error" class="error-box"></div>
<form id="login-form">
<label class="field-label" for="username">用户名</label>
<input class="text-input" id="username" name="username" autocomplete="username" required>
<label class="field-label" for="password">密码</label>
<input class="text-input" id="password" name="password" type="password" autocomplete="current-password" required>
<div class="admin-login-actions">
<button class="button primary" type="submit">登录</button>
<a class="button" href="/">返回入口</a>
<?php if ($archiveCaskUrl !== ''): ?>
<a class="button" href="<?=htmlspecialchars($archiveCaskUrl)?>">返回 Archive Cask</a>
<?php endif; ?>
</div>
</form>
<div class="admin-login-footnote">如忘记密码请联系数据库管理员。</div>
</section>
</main>
<script>
const form = document.getElementById('login-form');
const errorBox = document.getElementById('error');
form.addEventListener('submit', async (event) => {
event.preventDefault();
errorBox.style.display = 'none';
errorBox.textContent = '';
const payload = {
username: form.username.value.trim(),
password: form.password.value
};
try {
const response = await fetch('/api/admin/login', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(payload)
});
const data = await response.json();
if (!response.ok || data.code !== 0) {
throw new Error(data.errors?.auth || data.message || '登录失败。');
}
window.location.href = '/admin';
} catch (error) {
errorBox.textContent = error.message || '登录失败。';
errorBox.style.display = 'block';
}
});
</script>
</body>
</html>