This commit is contained in:
jeremygan2021
2026-03-20 16:18:58 +08:00
parent 3bdb055b83
commit 7caff4d72d
6 changed files with 312 additions and 31 deletions

View File

@@ -273,6 +273,18 @@
</style>
</head>
<body>
<!-- Password Overlay -->
<div id="password-overlay" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: var(--bg-color); z-index: 9999; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(10px);">
<div class="card" style="text-align: center; width: 90%; max-width: 400px;">
<h2 style="margin-bottom: 20px;">请输入访问密钥</h2>
<div class="input-group">
<input type="password" id="secret-input" placeholder="输入密钥" style="text-align: center;">
</div>
<button onclick="checkSecret()">确认</button>
<p id="secret-error" class="error-msg hidden">密钥错误</p>
</div>
</div>
<div class="container">
<header>
<img src="{{ config.header_image }}" alt="{{ config.event_title }}" class="header-img" onerror="this.style.display='none'">
@@ -384,6 +396,68 @@
</div>
<script>
document.addEventListener('DOMContentLoaded', checkAuthStatus);
async function checkAuthStatus() {
try {
const res = await fetch('/api/admin/check-auth');
const data = await res.json();
if (data.authenticated) {
hideOverlay();
} else {
showOverlay();
}
} catch (e) {
showOverlay();
}
}
function showOverlay() {
document.getElementById('password-overlay').style.display = 'flex';
}
function hideOverlay() {
const overlay = document.getElementById('password-overlay');
overlay.style.opacity = '0';
setTimeout(() => {
overlay.style.display = 'none';
}, 500);
}
async function checkSecret() {
const input = document.getElementById('secret-input');
const error = document.getElementById('secret-error');
const password = input.value;
try {
const res = await fetch('/api/admin/login', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({password: password})
});
const data = await res.json();
if (data.success) {
error.classList.add('hidden');
hideOverlay();
} else {
error.classList.remove('hidden');
input.value = '';
input.focus();
}
} catch (e) {
error.textContent = '网络错误';
error.classList.remove('hidden');
}
}
document.getElementById('secret-input').addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
checkSecret();
}
});
async function searchUser() {
const query = document.getElementById('search-input').value.trim();
const btn = document.getElementById('search-btn');