|
|
|
@ -0,0 +1,45 @@
|
|
|
|
|
using IdentitySvc.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace IdentitySvc.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class RegisterApiController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly UserManager<ApplicationUser> _userManager;
|
|
|
|
|
|
|
|
|
|
public RegisterApiController(UserManager<ApplicationUser> userManager)
|
|
|
|
|
{
|
|
|
|
|
_userManager = userManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> Register([FromBody] RegisterApiDto dto)
|
|
|
|
|
{
|
|
|
|
|
if (dto.Username != "Harry")
|
|
|
|
|
return BadRequest("Invalid registration data.");
|
|
|
|
|
var user = new ApplicationUser
|
|
|
|
|
{
|
|
|
|
|
UserName = dto.Username,
|
|
|
|
|
Email = dto.Email,
|
|
|
|
|
EmailConfirmed = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var result = await _userManager.CreateAsync(user, dto.Password);
|
|
|
|
|
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
return BadRequest(result.Errors);
|
|
|
|
|
|
|
|
|
|
return StatusCode(201);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RegisterApiDto
|
|
|
|
|
{
|
|
|
|
|
public string Username { get; set; }
|
|
|
|
|
public string Email { get; set; }
|
|
|
|
|
public string Password { get; set; }
|
|
|
|
|
}
|