This commit is contained in:
JakkrapartXD 2026-01-13 03:10:44 +00:00
parent a3da5c9d55
commit f026c14f0c
9 changed files with 7286 additions and 6 deletions

View file

@ -1,14 +1,17 @@
import { Body, Post, Route, Tags, SuccessResponse, Response, Example, Controller } from 'tsoa';
import { Body, Post, Route, Tags, SuccessResponse, Response, Example, Controller, Security } from 'tsoa';
import { AuthService } from '../services/auth.service';
import {
LoginRequest,
RegisterRequest,
RefreshTokenRequest,
ResetRequest,
ResetPasswordRequest,
LoginResponse,
RegisterResponse,
RefreshTokenResponse
RefreshTokenResponse,
ChangePassword
} from '../types/auth.types';
import { loginSchema, registerSchema, refreshTokenSchema } from '../validators/auth.validator';
import { loginSchema, registerSchema, refreshTokenSchema, resetRequestSchema, resetPasswordSchema, changePasswordSchema } from '../validators/auth.validator';
import { ValidationError } from '../middleware/errorHandler';
@Route('api/auth')
@ -126,4 +129,38 @@ export class AuthController {
return await this.authService.refreshToken(body.refreshToken);
}
@Post('reset-request')
@SuccessResponse('200', 'Reset request successful')
@Response('401', 'Invalid or expired refresh token')
public async resetRequest(@Body() body: ResetRequest): Promise<{ message: string }> {
const { error } = resetRequestSchema.validate(body);
if (error) {
throw new ValidationError(error.details[0].message);
}
return await this.authService.resetRequest(body.email);
}
@Post('reset-password')
@SuccessResponse('200', 'Password reset successful')
@Response('401', 'Invalid or expired reset token')
public async resetPassword(@Body() body: ResetPasswordRequest): Promise<{ message: string }> {
const { error } = resetPasswordSchema.validate(body);
if (error) {
throw new ValidationError(error.details[0].message);
}
return await this.authService.resetPassword(body.id, body.token, body.password);
}
@Post('change-password')
@Security('jwt')
@SuccessResponse('200', 'Password changed successfully')
@Response('401', 'Invalid or expired reset token')
public async changePassword(@Body() body: ChangePassword): Promise<{ message: string }> {
const { error } = changePasswordSchema.validate(body);
if (error) {
throw new ValidationError(error.details[0].message);
}
return await this.authService.changePassword(body.id, body.oldPassword, body.newPassword);
}
}