| | 1 | | using LGDXRobotCloud.API.Services.Identity; |
| | 2 | | using LGDXRobotCloud.Data.Models.Business.Identity; |
| | 3 | | using LGDXRobotCloud.Data.Models.DTOs.V1.Requests; |
| | 4 | | using LGDXRobotCloud.Data.Models.DTOs.V1.Responses; |
| | 5 | | using Microsoft.AspNetCore.Authentication.JwtBearer; |
| | 6 | | using Microsoft.AspNetCore.Authorization; |
| | 7 | | using Microsoft.AspNetCore.Mvc; |
| | 8 | |
|
| | 9 | | namespace LGDXRobotCloud.API.Areas.Identity.Controllers; |
| | 10 | |
|
| | 11 | | [ApiController] |
| | 12 | | [Area("Identity")] |
| | 13 | | [Route("[area]/[controller]")] |
| | 14 | | [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] |
| 0 | 15 | | public sealed class AuthController(IAuthService authService) : ControllerBase |
| | 16 | | { |
| 0 | 17 | | private readonly IAuthService _authService = authService ?? throw new ArgumentNullException(nameof(authService)); |
| | 18 | |
|
| | 19 | | [AllowAnonymous] |
| | 20 | | [HttpPost("Login")] |
| | 21 | | [ProducesResponseType(typeof(LoginResponseDto), StatusCodes.Status200OK)] |
| | 22 | | [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] |
| | 23 | | public async Task<ActionResult<LoginResponseDto>>Login(LoginRequestDto loginRequestDto) |
| 0 | 24 | | { |
| 0 | 25 | | var result = await _authService.LoginAsync(loginRequestDto.ToBusinessModel()); |
| 0 | 26 | | return Ok(result.ToDto()); |
| 0 | 27 | | } |
| | 28 | |
|
| | 29 | | [AllowAnonymous] |
| | 30 | | [HttpPost("ForgotPassword")] |
| | 31 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | 32 | | public async Task<ActionResult> ForgotPassword(ForgotPasswordRequestDto forgotPasswordRequestDto) |
| 0 | 33 | | { |
| 0 | 34 | | await _authService.ForgotPasswordAsync(forgotPasswordRequestDto.ToBusinessModel()); |
| 0 | 35 | | return Ok(); |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | [AllowAnonymous] |
| | 39 | | [HttpPost("ResetPassword")] |
| | 40 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | 41 | | [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] |
| | 42 | | public async Task<ActionResult> ResetPassword(ResetPasswordRequestDto resetPasswordRequestDto) |
| 0 | 43 | | { |
| 0 | 44 | | await _authService.ResetPasswordAsync(resetPasswordRequestDto.ToBusinessModel()); |
| 0 | 45 | | return Ok(); |
| 0 | 46 | | } |
| | 47 | |
|
| | 48 | | [AllowAnonymous] |
| | 49 | | [HttpPost("Refresh")] |
| | 50 | | [ProducesResponseType(typeof(RefreshTokenResponseDto), StatusCodes.Status200OK)] |
| | 51 | | [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] |
| | 52 | | public async Task<ActionResult> Refresh(RefreshTokenRequestDto refreshTokenRequestDto) |
| 0 | 53 | | { |
| 0 | 54 | | var result = await _authService.RefreshTokenAsync(refreshTokenRequestDto.ToBusinessModel()); |
| 0 | 55 | | return Ok(result.ToDto()); |
| 0 | 56 | | } |
| | 57 | | } |