Initial commit: page-manager Next.js app with Coolify deploy support
Replace Vercel-specific infra (Cron, Blob) with self-hosted equivalents for deployment to Coolify: in-container cron scheduler (scripts/cron-runner.mjs) and disk-based upload storage served via /api/uploads/[...path]. Add Dockerfile, .dockerignore, and /api/health for container health checks. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { MIN_PASSWORD_LENGTH } from "@/lib/auth/policy";
|
||||
|
||||
export default function ChangePasswordPage() {
|
||||
const router = useRouter();
|
||||
const [currentPassword, setCurrent] = useState("");
|
||||
const [newPassword, setNew] = useState("");
|
||||
const [confirm, setConfirm] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function submit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (newPassword !== confirm) return setError("รหัสผ่านใหม่ทั้งสองช่องไม่ตรงกัน");
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
const res = await fetch("/api/auth/change-password", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ currentPassword, newPassword }),
|
||||
});
|
||||
const body = await res.json().catch(() => ({}));
|
||||
setBusy(false);
|
||||
if (!res.ok) return setError(body.error ?? "เปลี่ยนรหัสผ่านไม่สำเร็จ");
|
||||
router.replace("/");
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
await fetch("/api/auth/logout", { method: "POST" });
|
||||
router.replace("/login");
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="min-h-screen grid place-items-center px-4">
|
||||
<form onSubmit={submit} className="card card-body flex flex-col gap-4 w-full max-w-[400px]" style={{ padding: 28 }}>
|
||||
<div>
|
||||
<h1 className="text-[22px] font-semibold">ตั้งรหัสผ่านใหม่</h1>
|
||||
<p className="text-ink-3">ต้องตั้งรหัสผ่านของคุณเองก่อนใช้งาน (อย่างน้อย {MIN_PASSWORD_LENGTH} ตัวอักษร)</p>
|
||||
</div>
|
||||
<label className="field">
|
||||
<span>รหัสผ่านปัจจุบัน</span>
|
||||
<input className="input" type="password" autoComplete="current-password" required value={currentPassword} onChange={(e) => setCurrent(e.target.value)} />
|
||||
</label>
|
||||
<label className="field">
|
||||
<span>รหัสผ่านใหม่</span>
|
||||
<input className="input" type="password" autoComplete="new-password" required minLength={MIN_PASSWORD_LENGTH} value={newPassword} onChange={(e) => setNew(e.target.value)} />
|
||||
</label>
|
||||
<label className="field">
|
||||
<span>ยืนยันรหัสผ่านใหม่</span>
|
||||
<input className="input" type="password" autoComplete="new-password" required value={confirm} onChange={(e) => setConfirm(e.target.value)} />
|
||||
</label>
|
||||
{error && (
|
||||
<p className="notice notice-red" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<button className="btn btn-primary btn-lg" disabled={busy}>
|
||||
{busy ? "กำลังบันทึก…" : "บันทึกรหัสผ่าน"}
|
||||
</button>
|
||||
<button type="button" className="btn btn-ghost" onClick={logout}>
|
||||
ออกจากระบบ
|
||||
</button>
|
||||
</form>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user