.Net Core : Register User data into Identity table
Insert record in identity table,
namespace DotNetCoreDemo.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class AccountController : Controller
{
private readonly UserManager<IdentityUser> userManager;
private readonly SignInManager<IdentityUser> signInManager;
public AccountController(UserManager<IdentityUser> userManager, SignInManager<IdentityUser> signInManager)
{
this.userManager = userManager;
this.signInManager = signInManager;
}
[HttpPost]
[Route("Register")]
public async Task<JsonResult> Post(VMRegister vmRegister)
{
IdentityResult result = new IdentityResult();
string errorMessage = "success";
if(ModelState.IsValid)
{
var user = new IdentityUser
{
UserName = vmRegister.Email,
Email = vmRegister.Email
};
result = await userManager.CreateAsync(user, vmRegister.Password);
if(result.Succeeded)
{
//to Signin user
//signInManager.SignInAsync(user, isPersistent: false).Start();
}
else
{
if(result.Errors.Count() > 0)
{
errorMessage = "";
foreach (var error in result.Errors)
{
errorMessage += error.Description;
}
}
}
}
return Json(new { id = "1", message = errorMessage });
}
}
}
Hope this will help you and save your time.
Enjoy !!!
:)
Casino Slots Apps | Download App For Android & iPhone
ReplyDeleteAt Casino Slots App, you can easily have 문경 출장안마 your favorite slot machines and slots, all in 서울특별 출장마사지 one place. 화성 출장안마 You have access to 1xbet login over 250,000 casino games, from the 파주 출장샵