Application mono-utilisateur : inscription unique, connexion par JWT (12 h), protection de toutes les routes de données, réinitialisation de mot de passe par email avec repli de journalisation, onboarding réorganisé en deux étapes (inscription → connexion → profil + véhicule). Backend (SchotzIadKmTracker.Api) : - Entités Compte (singleton) et ResetPasswordToken + migration AjoutAuthentification. - Hachage PasswordHasher, JwtService (HS256, durée configurable), IEmailService (MailKit + repli LoggingEmailService selon Smtp:Host). - AuthService (register 409 si compte existant, login 401 générique, forgot-password non-divulgation, reset à usage unique + expiration), AuthController (5 endpoints publics), DTOs + validateurs FluentValidation. - Sécurité pipeline : JwtBearer + filtre d'autorisation global, UseAuthentication avant UseAuthorization ; /health et /api/auth/* publics. Frontend (schotziad-km-tracker, zoneless + signals) : - AuthService (localStorage), authInterceptor (Bearer + purge/redirection 401), authGuard, écrans Login/Register/ForgotPassword/ResetPassword, routes publiques et protection [authGuard, profilConfigureGuard]. Configuration : .env.example et docker-compose.yml (JWT__SecretKey, durées, Smtp__*). Tests : 54 tests backend (propriétés FsCheck P1–P14, exemples, intégration WebApplicationFactory) + tests frontend (AuthService, authGuard, authInterceptor, ResetPasswordComponent). Suite complète au vert. Spec : .kiro/specs/authentification (requirements, design, tasks).
59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
using FluentValidation;
|
|
using SchotzIadKmTracker.Api.Models.DTOs;
|
|
|
|
namespace SchotzIadKmTracker.Api.Validators;
|
|
|
|
// Validation de l'inscription (Requirements 1.3, 1.4, 8.2).
|
|
public class RegisterDtoValidator : AbstractValidator<RegisterDto>
|
|
{
|
|
public RegisterDtoValidator()
|
|
{
|
|
RuleFor(x => x.Email)
|
|
.NotEmpty().WithMessage("L'adresse email est obligatoire.")
|
|
.EmailAddress().WithMessage("Adresse email invalide.");
|
|
|
|
RuleFor(x => x.MotDePasse)
|
|
.NotEmpty().WithMessage("Le mot de passe est obligatoire.")
|
|
.MinimumLength(8).WithMessage("Le mot de passe doit comporter au moins 8 caractères.");
|
|
}
|
|
}
|
|
|
|
// Validation de la connexion (Requirements 1.4, 2.2).
|
|
public class LoginDtoValidator : AbstractValidator<LoginDto>
|
|
{
|
|
public LoginDtoValidator()
|
|
{
|
|
RuleFor(x => x.Email)
|
|
.NotEmpty().WithMessage("L'adresse email est obligatoire.")
|
|
.EmailAddress().WithMessage("Adresse email invalide.");
|
|
|
|
RuleFor(x => x.MotDePasse)
|
|
.NotEmpty().WithMessage("Le mot de passe est obligatoire.");
|
|
}
|
|
}
|
|
|
|
// Validation de la demande de réinitialisation (Requirements 1.4, 6).
|
|
public class ForgotPasswordDtoValidator : AbstractValidator<ForgotPasswordDto>
|
|
{
|
|
public ForgotPasswordDtoValidator()
|
|
{
|
|
RuleFor(x => x.Email)
|
|
.NotEmpty().WithMessage("L'adresse email est obligatoire.")
|
|
.EmailAddress().WithMessage("Adresse email invalide.");
|
|
}
|
|
}
|
|
|
|
// Validation de la réinitialisation du mot de passe (Requirements 7.4, 7.5).
|
|
public class ResetPasswordDtoValidator : AbstractValidator<ResetPasswordDto>
|
|
{
|
|
public ResetPasswordDtoValidator()
|
|
{
|
|
RuleFor(x => x.Token)
|
|
.NotEmpty().WithMessage("Le jeton de réinitialisation est obligatoire.");
|
|
|
|
RuleFor(x => x.NouveauMotDePasse)
|
|
.NotEmpty().WithMessage("Le mot de passe est obligatoire.")
|
|
.MinimumLength(8).WithMessage("Le mot de passe doit comporter au moins 8 caractères.");
|
|
}
|
|
}
|