first commit

This commit is contained in:
2026-09-11 15:49:41 +08:00
commit 5b69bc818a
98 changed files with 30551 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
---
import { checkPassword, createSession, SESSION_COOKIE, sessionCookieOptions } from "../../lib/auth";
import { getEnv } from "../../lib/env";
export const prerender = false;
let error = "";
if (Astro.request.method === "POST") {
const form = await Astro.request.formData();
const password = String(form.get("password") ?? "");
const secret = getEnv().ADMIN_PASSWORD!;
if (await checkPassword(password, secret)) {
Astro.cookies.set(SESSION_COOKIE, await createSession(secret), sessionCookieOptions);
return Astro.redirect("/admin");
}
error = "密碼唔啱。";
}
---
<!doctype html>
<html lang="zh-Hant">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>登入後台</title>
<meta name="robots" content="noindex, nofollow" />
</head>
<body>
<main>
<h1>登入後台</h1>
{error && <p class="err">{error}</p>}
<form method="post">
<label for="password">密碼</label>
<input id="password" name="password" type="password" autofocus required />
<div class="actions">
<button type="submit">登入</button>
</div>
</form>
</main>
</body>
</html>
<style is:global>
:root {
font-family: -apple-system, BlinkMacSystemFont, "PingFang HK", "Noto Sans HK", sans-serif;
color: #2c2c2a; background: #f7f7f5; line-height: 1.65; font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; display: flex; align-items: center; justify-content: center; min-height: 100vh; }
main { width: 100%; max-width: 360px; padding: 32px; background: #fff; border: 1px solid rgba(0,0,0,.08); border-radius: 12px; }
h1 { font-size: 18px; font-weight: 500; margin: 0 0 20px; }
label { display: block; font-size: 13px; color: #5f5e5a; margin-bottom: 6px; }
input { width: 100%; font: inherit; font-size: 14px; padding: 9px 12px; border: 1px solid rgba(0,0,0,.15); border-radius: 8px; }
input:focus { outline: 2px solid #b5d4f4; border-color: #185fa5; }
button { margin-top: 18px; width: 100%; font: inherit; font-size: 14px; padding: 9px 18px; border-radius: 8px; cursor: pointer; border: 1px solid #185fa5; background: #185fa5; color: #fff; }
.err { background: #fcebeb; color: #a32d2d; padding: 10px 14px; border-radius: 8px; font-size: 14px; margin: 0 0 16px; }
</style>