new
This commit is contained in:
@@ -297,28 +297,62 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Use secret from backend
|
||||
const ACCESS_SECRET = "{{ secret }}";
|
||||
document.addEventListener('DOMContentLoaded', checkAuthStatus);
|
||||
|
||||
// Password Check Logic
|
||||
function checkSecret() {
|
||||
const input = document.getElementById('secret-input');
|
||||
const error = document.getElementById('secret-error');
|
||||
const overlay = document.getElementById('password-overlay');
|
||||
|
||||
if (input.value === ACCESS_SECRET) {
|
||||
overlay.style.opacity = '0';
|
||||
setTimeout(() => {
|
||||
overlay.style.display = 'none';
|
||||
}, 500);
|
||||
} else {
|
||||
error.classList.remove('hidden');
|
||||
input.value = '';
|
||||
input.focus();
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
// Allow pressing Enter to submit password
|
||||
document.getElementById('secret-input').addEventListener('keypress', function (e) {
|
||||
if (e.key === 'Enter') {
|
||||
checkSecret();
|
||||
|
||||
Reference in New Issue
Block a user