registration and authorization
This commit is contained in:
parent
2b5f468b84
commit
4423dc360f
12 changed files with 136 additions and 6 deletions
|
|
@ -1,5 +1,7 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using SurveyBackend.DTOs;
|
||||
using SurveyBackend.Infrastructure.Services;
|
||||
using SurveyBackend.Mappers.UserDTOs;
|
||||
|
||||
namespace SurveyBackend.Controllers;
|
||||
|
||||
|
|
@ -7,9 +9,32 @@ namespace SurveyBackend.Controllers;
|
|||
[Route("auth")]
|
||||
public class AuthController : ControllerBase
|
||||
{
|
||||
[HttpPost("login")]
|
||||
public async Task<IActionResult> GetToken([FromBody] UserLoginDto loginData)
|
||||
private readonly AuthorizationService _authorizationService;
|
||||
|
||||
public AuthController(AuthorizationService authorizationService)
|
||||
{
|
||||
_authorizationService = authorizationService;
|
||||
}
|
||||
|
||||
[HttpPost("login")]
|
||||
public async Task<IActionResult> LogIn([FromBody] UserLoginDto loginData)
|
||||
{
|
||||
var token = await _authorizationService.LogInUser(loginData.Email, loginData.Password);
|
||||
return token is null ? Unauthorized() : Ok(new { token = token });
|
||||
}
|
||||
|
||||
[HttpPost("register")]
|
||||
public async Task<IActionResult> Register([FromBody] UserRegistrationDto registerData)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _authorizationService.RegisterUser(UserRegistrationMapper.UserRegistrationToModel(registerData));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue