mirror of
https://github.com/arthur-pbty/contact.git
synced 2026-06-03 23:36:30 +02:00
feat: add contact page with form handling and validation
- Implemented a contact page with a form for user inquiries. - Added validation for form fields using Zod schema. - Integrated PostgreSQL database for storing contact messages. - Created necessary API endpoints for form submission. - Added admin authentication and session management. - Developed CGU, cookies policy, privacy policy, and legal mentions pages. - Set up Docker configuration for PostgreSQL and application services. - Enhanced UI with responsive design and accessibility features.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { createAdminToken, getAdminCookieName, getAdminCredentials } from "@/lib/admin-auth";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = (await request.json().catch(() => null)) as
|
||||
| { username?: string; password?: string }
|
||||
| null;
|
||||
|
||||
if (!body?.username || !body?.password) {
|
||||
return NextResponse.json({ message: "Identifiants manquants." }, { status: 400 });
|
||||
}
|
||||
|
||||
const credentials = getAdminCredentials();
|
||||
if (body.username !== credentials.username || body.password !== credentials.password) {
|
||||
return NextResponse.json({ message: "Identifiants invalides." }, { status: 401 });
|
||||
}
|
||||
|
||||
const token = createAdminToken(body.username);
|
||||
const response = NextResponse.json({ ok: true });
|
||||
response.cookies.set(getAdminCookieName(), token, {
|
||||
httpOnly: true,
|
||||
sameSite: "lax",
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
path: "/",
|
||||
maxAge: 60 * 60 * 12,
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
Reference in New Issue
Block a user