39 lines
952 B
C#
39 lines
952 B
C#
using HackerNet.Api.Models;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace HackerNet.Api.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("/api/accounts")]
|
|
public class AccountsController : ControllerBase
|
|
{
|
|
private readonly UserManager<IdentityUser> _userManager;
|
|
private readonly SignInManager<IdentityUser> _signInManager;
|
|
|
|
public AccountsController(UserManager<IdentityUser> userManager, SignInManager<IdentityUser> signInManager)
|
|
{
|
|
_userManager = userManager;
|
|
_signInManager = signInManager;
|
|
}
|
|
|
|
[HttpGet("me")]
|
|
public ActionResult Me()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<ActionResult> Signup(SignupLoginViewModel cmd)
|
|
{
|
|
var user = new IdentityUser(cmd.Username);
|
|
var result = await _userManager.CreateAsync(user, cmd.Password);
|
|
|
|
if (!result.Succeeded)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
|
|
return CreatedAtAction(nameof(Me), null);
|
|
}
|
|
} |