public async Task<IActionResult> RegisterWebshopUser(WebshopUserDto webshopUser)
{
try
{
var existingUser = await this.UserManager.FindByEmailAsync(webshopUser.Email);
if (existingUser == null)
{
var user = new ApplicationUser
{
UserName = webshopUser.First + webshopUser.Last,
Email = webshopUser.Email,
RegisteredOn = DateTime.Now,
NeedToChangePassword = false,
UserType = UserTypes.WebUser,
EmailConfirmed = true,
IsEnabled = true
};
var result = await this.UserManager.CreateAsync(user, webshopUser.Password);
if (result.Succeeded)
{
await this.UserManager.AddClaimsAsync(user, new[]
{
new Claim(JwtClaimTypes.FamilyName, webshopUser.Last),
new Claim(JwtClaimTypes.GivenName, webshopUser.First)
});
}
var newUser = await this.UserManager.FindByEmailAsync(webshopUser.Email);
return Created("User created", newUser);
}
//
}