feat(auth): #127 forgot-password + reset-password API (BDD + mail)
Made-with: Cursor
This commit is contained in:
@@ -1,4 +1,17 @@
|
||||
import { Body, Controller, Get, Patch, Post, Query, Req, UnauthorizedException, BadRequestException, UseGuards } from '@nestjs/common';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
Req,
|
||||
UnauthorizedException,
|
||||
BadRequestException,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { LoginDto } from './dto/login.dto';
|
||||
import { AuthService } from './auth.service';
|
||||
import { Public } from 'src/common/decorators/public.decorator';
|
||||
@@ -8,6 +21,8 @@ import { RegisterAMCompletDto } from './dto/register-am-complet.dto';
|
||||
import { RegisterAmResponseDto } from './dto/register-am-response.dto';
|
||||
import { ChangePasswordRequiredDto } from './dto/change-password.dto';
|
||||
import { CreatePasswordDto } from './dto/create-password.dto';
|
||||
import { ForgotPasswordDto } from './dto/forgot-password.dto';
|
||||
import { ResetPasswordDto } from './dto/reset-password.dto';
|
||||
import { ApiBearerAuth, ApiOperation, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { AuthGuard } from 'src/common/guards/auth.guard';
|
||||
import type { Request } from 'express';
|
||||
@@ -133,6 +148,36 @@ export class AuthController {
|
||||
return this.authService.createPasswordWithToken(dto.token, dto.password);
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Post('forgot-password')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({
|
||||
summary: 'Demande de réinitialisation du mot de passe (ticket #127)',
|
||||
description:
|
||||
'Réponse identique que l’e-mail existe ou non (anti-énumération). Si un compte avec mot de passe existe, un e-mail avec lien /reset-password est envoyé.',
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Message générique' })
|
||||
async forgotPassword(@Body() dto: ForgotPasswordDto) {
|
||||
return this.authService.requestPasswordReset(dto.email ?? '');
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Post('reset-password')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({
|
||||
summary: 'Réinitialiser le mot de passe via token e-mail (ticket #127)',
|
||||
description: 'Distinct de POST /auth/create-password (inscription). Utilise password_reset_token.',
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Mot de passe mis à jour' })
|
||||
@ApiResponse({ status: 400, description: 'Confirmation ou règles de mot de passe' })
|
||||
@ApiResponse({ status: 404, description: 'Token invalide, expiré, ou déjà utilisé' })
|
||||
async resetPassword(@Body() dto: ResetPasswordDto) {
|
||||
if (dto.password !== dto.password_confirmation) {
|
||||
throw new BadRequestException('Les mots de passe ne correspondent pas');
|
||||
}
|
||||
return this.authService.resetPasswordWithResetToken(dto.token, dto.password);
|
||||
}
|
||||
|
||||
@Get('me')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiBearerAuth('access-token')
|
||||
|
||||
Reference in New Issue
Block a user