2021-11-11 21:54:11 +01:00

35 lines
965 B
C#

using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Todo.Core.Interfaces.Persistence;
namespace Todo.Api.Controllers
{
[ApiController]
[Route("api/auth")]
[Authorize]
[AllowAnonymous]
public class AuthController : ControllerBase
{
private readonly IUserRepository _userRepository;
public AuthController(IUserRepository userRepository)
{
_userRepository = userRepository;
}
[HttpPost("register")]
public async Task<IActionResult> Register([FromBody] RegisterUserRequest request)
{
var user = await _userRepository.Register(request.Email, request.Password);
return Ok(user);
}
public record RegisterUserRequest
{
[Required] public string Email { get; init; }
[Required] public string Password { get; init; }
}
}
}