diff --git a/Govor.API/Controllers/AdminStuff/InviteUserController.cs b/Govor.API/Controllers/AdminStuff/InviteUserController.cs index 44d85c1..4b8893f 100644 --- a/Govor.API/Controllers/AdminStuff/InviteUserController.cs +++ b/Govor.API/Controllers/AdminStuff/InviteUserController.cs @@ -3,11 +3,14 @@ using Govor.API.Services.AdminsStuff.Interfaces; using Govor.Core.DTOs; using Govor.Core.Repositories.Invaites; using Govor.Core.Requests; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Govor.API.Controllers.AdminStuff; [Route("api/[controller]")] +[ApiController] +[Authorize] public class InviteUserController : Controller { private readonly IInvitesRepository _repository; diff --git a/Govor.API/Controllers/AuthController.cs b/Govor.API/Controllers/AuthController.cs index 8e0ffe5..8e4c9bb 100644 --- a/Govor.API/Controllers/AuthController.cs +++ b/Govor.API/Controllers/AuthController.cs @@ -23,7 +23,7 @@ public class AuthController : Controller [HttpPost("register")]// api/auth/register [RequireHttps] - public async Task Register([FromBody] RegistrationDto registrationDto) + public async Task Register([FromBody] RegistrationRequest registrationRequest) { try { @@ -32,32 +32,32 @@ public class AuthController : Controller return BadRequest(ModelState); } - var invite = _invitesService.Validate(registrationDto.InviteLink); + var invite = _invitesService.Validate(registrationRequest.InviteLink); - var token = await _accountService.RegistrationAsync(registrationDto.Name, registrationDto.Password, invite); - _logger.LogInformation($"Register request for {registrationDto.Name}"); + var token = await _accountService.RegistrationAsync(registrationRequest.Name, registrationRequest.Password, invite); + _logger.LogInformation($"Register request for {registrationRequest.Name}"); return Ok(new { token }); } catch (UserAlreadyExistException ex) { - _logger.LogWarning(ex, $"Registration failed for user {registrationDto.Name}"); + _logger.LogWarning(ex, $"Registration failed for user {registrationRequest.Name}"); return BadRequest("Registration failed: user already exists."); } catch (InviteLinkInvalidException ex) { - _logger.LogWarning(ex, $"Invite link invalid: {registrationDto.InviteLink}"); + _logger.LogWarning(ex, $"Invite link invalid: {registrationRequest.InviteLink}"); return BadRequest("Invite link invalid."); } catch (Exception ex) { - _logger.LogError(ex, "Unexpected error during registration for user {Name}", registrationDto.Name); + _logger.LogError(ex, "Unexpected error during registration for user {Name}", registrationRequest.Name); return StatusCode(500, "An unexpected error occurred. Please try again later."); } } [HttpPost("login")]// api/auth/login [RequireHttps] - public async Task Login([FromBody] LoginDto userDto) + public async Task Login([FromBody] LoginRequest userRequest) { try { @@ -66,18 +66,18 @@ public class AuthController : Controller return BadRequest(ModelState); } - var token = await _accountService.LoginAsync(userDto.Name, userDto.Password); - _logger.LogInformation($"Login request for {userDto.Name}"); + var token = await _accountService.LoginAsync(userRequest.Name, userRequest.Password); + _logger.LogInformation($"Login request for {userRequest.Name}"); return Ok(new { token }); } catch (UserNotRegisteredException ex) { - _logger.LogWarning(ex, "Login failed for user {Name}", userDto.Name); + _logger.LogWarning(ex, "Login failed for user {Name}", userRequest.Name); return BadRequest("Login failed: user does not exist."); } catch (Exception ex) { - _logger.LogError(ex, "Unexpected error during login for user {Name}", userDto.Name); + _logger.LogError(ex, "Unexpected error during login for user {Name}", userRequest.Name); return StatusCode(500, "An unexpected error occurred. Please try again later."); } } diff --git a/Govor.Console/Program.cs b/Govor.Console/Program.cs index 86f9486..0808d30 100644 --- a/Govor.Console/Program.cs +++ b/Govor.Console/Program.cs @@ -74,7 +74,7 @@ class Program { try { - RegistrationDto loginData = new RegistrationDto() + RegistrationRequest loginData = new RegistrationRequest() { Name = username, Password = password diff --git a/Govor.Core/DTOs/LoginDto.cs b/Govor.Core/Requests/LoginRequest.cs similarity index 87% rename from Govor.Core/DTOs/LoginDto.cs rename to Govor.Core/Requests/LoginRequest.cs index 6ca8e67..2779aa8 100644 --- a/Govor.Core/DTOs/LoginDto.cs +++ b/Govor.Core/Requests/LoginRequest.cs @@ -1,9 +1,9 @@ using System.ComponentModel.DataAnnotations; using Govor.Core.Infrastructure.Validators; -namespace Govor.Core.DTOs; +namespace Govor.Core.Requests; -public class LoginDto +public class LoginRequest { [Required] [StringLength(UserValidator.MAX_LENGHT_OF_NAME, diff --git a/Govor.Core/DTOs/RegistrationDto.cs b/Govor.Core/Requests/RegistrationRequest.cs similarity index 89% rename from Govor.Core/DTOs/RegistrationDto.cs rename to Govor.Core/Requests/RegistrationRequest.cs index dc32a91..40c7290 100644 --- a/Govor.Core/DTOs/RegistrationDto.cs +++ b/Govor.Core/Requests/RegistrationRequest.cs @@ -2,9 +2,9 @@ using System.ComponentModel.DataAnnotations; using Govor.Core.Infrastructure.Validators; using Govor.Core.Models; -namespace Govor.Core.DTOs; +namespace Govor.Core.Requests; -public record RegistrationDto +public record RegistrationRequest { [Required] [StringLength(UserValidator.MAX_LENGHT_OF_NAME,