| | 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 LGDXRobotCloud.Utilities.Constants; |
| | 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 = LgdxRobotCloudAuthenticationSchemes.ApiKeyOrCertificationScheme)] |
| 0 | 15 | | public sealed class AuthController(IAuthService authService) : ControllerBase |
| | 16 | | { |
| 0 | 17 | | private readonly IAuthService _authService = authService ?? throw new ArgumentNullException(nameof(authService)); |
| | 18 | |
|
| | 19 | | [HttpPost("Login")] |
| | 20 | | [ProducesResponseType(typeof(LoginResponseDto), StatusCodes.Status200OK)] |
| | 21 | | [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] |
| | 22 | | public async Task<ActionResult<LoginResponseDto>>Login(LoginRequestDto loginRequestDto) |
| 0 | 23 | | { |
| 0 | 24 | | var result = await _authService.LoginAsync(loginRequestDto.ToBusinessModel()); |
| 0 | 25 | | return Ok(result.ToDto()); |
| 0 | 26 | | } |
| | 27 | |
|
| | 28 | | [HttpPost("ForgotPassword")] |
| | 29 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | 30 | | public async Task<ActionResult> ForgotPassword(ForgotPasswordRequestDto forgotPasswordRequestDto) |
| 0 | 31 | | { |
| 0 | 32 | | await _authService.ForgotPasswordAsync(forgotPasswordRequestDto.ToBusinessModel()); |
| 0 | 33 | | return Ok(); |
| 0 | 34 | | } |
| | 35 | |
|
| | 36 | | [HttpPost("ResetPassword")] |
| | 37 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | 38 | | [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] |
| | 39 | | public async Task<ActionResult> ResetPassword(ResetPasswordRequestDto resetPasswordRequestDto) |
| 0 | 40 | | { |
| 0 | 41 | | await _authService.ResetPasswordAsync(resetPasswordRequestDto.ToBusinessModel()); |
| 0 | 42 | | return Ok(); |
| 0 | 43 | | } |
| | 44 | |
|
| | 45 | | [HttpPost("Refresh")] |
| | 46 | | [ProducesResponseType(typeof(RefreshTokenResponseDto), StatusCodes.Status200OK)] |
| | 47 | | [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] |
| | 48 | | public async Task<ActionResult> Refresh(RefreshTokenRequestDto refreshTokenRequestDto) |
| 0 | 49 | | { |
| 0 | 50 | | var result = await _authService.RefreshTokenAsync(refreshTokenRequestDto.ToBusinessModel()); |
| 0 | 51 | | return Ok(result.ToDto()); |
| 0 | 52 | | } |
| | 53 | | } |