public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new User { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); //await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <User> Add(User entity, string password, string[] roles = null) { if (String.IsNullOrWhiteSpace(password)) { throw new BusinessException(MessageText.PleaseWritePassword); } using (PasswordBoxUserManager manager = PasswordBoxUserManager.Create()) { IdentityResult result = await manager.CreateAsync(entity, password); if (!result.Succeeded) { throw new BusinessException(result.Errors.Select(a => a.Description).ToList()); } if (roles != null) { await manager.AddToRolesAsync(entity, roles); } } return(entity); }