Spaces:
Sleeping
Sleeping
ichieh commited on
Commit ·
40ff339
1
Parent(s): 5e9fba9
Improve admin login page with better UI and proper redirection
Browse files- templates/admin_login.html +27 -4
templates/admin_login.html
CHANGED
|
@@ -5,6 +5,7 @@
|
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>管理者登入</title>
|
| 7 |
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
|
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
<div class="container mt-5">
|
|
@@ -20,7 +21,10 @@
|
|
| 20 |
<label for="password" class="form-label">密碼</label>
|
| 21 |
<input type="password" class="form-control" id="password" required>
|
| 22 |
</div>
|
| 23 |
-
<
|
|
|
|
|
|
|
|
|
|
| 24 |
</form>
|
| 25 |
</div>
|
| 26 |
</div>
|
|
@@ -29,6 +33,7 @@
|
|
| 29 |
</div>
|
| 30 |
|
| 31 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
|
|
| 32 |
<script>
|
| 33 |
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
| 34 |
e.preventDefault();
|
|
@@ -43,13 +48,31 @@
|
|
| 43 |
body: JSON.stringify({ password })
|
| 44 |
});
|
| 45 |
|
|
|
|
|
|
|
| 46 |
if (response.ok) {
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
} else {
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
}
|
| 51 |
} catch (error) {
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
}
|
| 54 |
});
|
| 55 |
</script>
|
|
|
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>管理者登入</title>
|
| 7 |
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 8 |
+
<link href="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.css" rel="stylesheet">
|
| 9 |
</head>
|
| 10 |
<body>
|
| 11 |
<div class="container mt-5">
|
|
|
|
| 21 |
<label for="password" class="form-label">密碼</label>
|
| 22 |
<input type="password" class="form-control" id="password" required>
|
| 23 |
</div>
|
| 24 |
+
<div class="d-grid gap-2">
|
| 25 |
+
<button type="submit" class="btn btn-primary">登入</button>
|
| 26 |
+
<a href="/" class="btn btn-secondary">返回首頁</a>
|
| 27 |
+
</div>
|
| 28 |
</form>
|
| 29 |
</div>
|
| 30 |
</div>
|
|
|
|
| 33 |
</div>
|
| 34 |
|
| 35 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
| 36 |
+
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.js"></script>
|
| 37 |
<script>
|
| 38 |
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
| 39 |
e.preventDefault();
|
|
|
|
| 48 |
body: JSON.stringify({ password })
|
| 49 |
});
|
| 50 |
|
| 51 |
+
const data = await response.json();
|
| 52 |
+
|
| 53 |
if (response.ok) {
|
| 54 |
+
Swal.fire({
|
| 55 |
+
icon: 'success',
|
| 56 |
+
title: '登入成功!',
|
| 57 |
+
text: '即將進入管理頁面...',
|
| 58 |
+
timer: 1500,
|
| 59 |
+
showConfirmButton: false
|
| 60 |
+
}).then(() => {
|
| 61 |
+
window.location.href = '/admin';
|
| 62 |
+
});
|
| 63 |
} else {
|
| 64 |
+
Swal.fire({
|
| 65 |
+
icon: 'error',
|
| 66 |
+
title: '登入失敗',
|
| 67 |
+
text: data.error || '密碼錯誤'
|
| 68 |
+
});
|
| 69 |
}
|
| 70 |
} catch (error) {
|
| 71 |
+
Swal.fire({
|
| 72 |
+
icon: 'error',
|
| 73 |
+
title: '登入失敗',
|
| 74 |
+
text: '系統錯誤,請稍後再試'
|
| 75 |
+
});
|
| 76 |
}
|
| 77 |
});
|
| 78 |
</script>
|