feat: implement user account management features including profile display and password change functionality

This commit is contained in:
Julien Froidefond
2025-10-16 22:27:06 +02:00
parent 3cd58f63e6
commit 83f523c11a
11 changed files with 501 additions and 1 deletions

34
src/app/account/page.tsx Normal file
View File

@@ -0,0 +1,34 @@
import { UserProfileCard } from "@/components/account/UserProfileCard";
import { ChangePasswordForm } from "@/components/account/ChangePasswordForm";
import { UserService } from "@/lib/services/user.service";
import { redirect } from "next/navigation";
export default async function AccountPage() {
try {
const [profile, stats] = await Promise.all([
UserService.getUserProfile(),
UserService.getUserStats(),
]);
return (
<div className="container mx-auto px-4 py-8">
<div className="max-w-4xl mx-auto space-y-8">
<div>
<h1 className="text-3xl font-bold">Mon compte</h1>
<p className="text-muted-foreground mt-2">
Gérez vos informations personnelles et votre sécurité
</p>
</div>
<div className="grid gap-6 md:grid-cols-2">
<UserProfileCard profile={{ ...profile, stats }} />
<ChangePasswordForm />
</div>
</div>
</div>
);
} catch (error) {
console.error("Erreur lors du chargement du compte:", error);
redirect("/login");
}
}

View File

@@ -0,0 +1,49 @@
import { NextRequest, NextResponse } from "next/server";
import { UserService } from "@/lib/services/user.service";
import { AppError } from "@/utils/errors";
import { AuthServerService } from "@/lib/services/auth-server.service";
export async function PUT(request: NextRequest) {
try {
const body = await request.json();
const { currentPassword, newPassword } = body;
if (!currentPassword || !newPassword) {
return NextResponse.json(
{ error: "Mots de passe manquants" },
{ status: 400 }
);
}
// Vérifier que le nouveau mot de passe est fort
if (!AuthServerService.isPasswordStrong(newPassword)) {
return NextResponse.json(
{
error: "Le nouveau mot de passe doit contenir au moins 8 caractères, une majuscule et un chiffre"
},
{ status: 400 }
);
}
await UserService.changePassword(currentPassword, newPassword);
return NextResponse.json({ success: true });
} catch (error) {
console.error("Erreur lors du changement de mot de passe:", error);
if (error instanceof AppError) {
return NextResponse.json(
{ error: error.message, code: error.code },
{
status: error.code === "AUTH_INVALID_PASSWORD" ? 400 :
error.code === "AUTH_UNAUTHENTICATED" ? 401 : 500
}
);
}
return NextResponse.json(
{ error: "Erreur lors du changement de mot de passe" },
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,28 @@
import { NextResponse } from "next/server";
import { UserService } from "@/lib/services/user.service";
import { AppError } from "@/utils/errors";
export async function GET() {
try {
const [profile, stats] = await Promise.all([
UserService.getUserProfile(),
UserService.getUserStats(),
]);
return NextResponse.json({ ...profile, stats });
} catch (error) {
console.error("Erreur lors de la récupération du profil:", error);
if (error instanceof AppError) {
return NextResponse.json(
{ error: error.message, code: error.code },
{ status: error.code === "AUTH_UNAUTHENTICATED" ? 401 : 500 }
);
}
return NextResponse.json(
{ error: "Erreur lors de la récupération du profil" },
{ status: 500 }
);
}
}