Spaces:
Sleeping
Sleeping
File size: 3,233 Bytes
c65e601 40ff339 c65e601 40ff339 c65e601 40ff339 c65e601 40ff339 90d34ea 40ff339 90d34ea 40ff339 c65e601 40ff339 c65e601 90d34ea 40ff339 c65e601 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | <!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>管理者登入</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h3 class="text-center">管理者登入</h3>
</div>
<div class="card-body">
<form id="loginForm">
<div class="mb-3">
<label for="password" class="form-label">密碼</label>
<input type="password" class="form-control" id="password" required>
</div>
<div class="d-grid gap-2">
<button type="submit" class="btn btn-primary">登入</button>
<a href="/" class="btn btn-secondary">返回首頁</a>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.js"></script>
<script>
document.getElementById('loginForm').addEventListener('submit', async (e) => {
e.preventDefault();
const password = document.getElementById('password').value;
try {
const response = await fetch('/api/admin/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ password })
});
const data = await response.json();
if (data.success) {
Swal.fire({
icon: 'success',
title: '登入成功!',
text: '即將進入管理頁面...',
timer: 1500,
showConfirmButton: false
}).then(() => {
window.location.replace('/admin');
});
} else {
Swal.fire({
icon: 'error',
title: '登入失敗',
text: data.error || '密碼錯誤'
});
}
} catch (error) {
console.error('Login error:', error);
Swal.fire({
icon: 'error',
title: '登入失敗',
text: '系統錯誤,請稍後再試'
});
}
});
</script>
</body>
</html>
|