public async Task <IActionResult> RegisterAssistant(RegisterAssistantViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var result2 = await _userManager.AddToRoleAsync(user, UserRoles.Assistant.ToString()); if (result2.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.SendAssistantEmailConfirmationAsync(model, 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 static Task SendAssistantEmailConfirmationAsync(this IEmailSender emailSender, RegisterAssistantViewModel model, string link) { return(emailSender.SendEmailAsync(AssistantConfirmerEmail, $"Confirm {model.FirstName} {model.LastName} email", "Assistant details:\n" + $"First name: {model.FirstName}\n" + $"Last name: {model.LastName}\n" + $"Email: {model.Email}\n" + $"Secret word: {model.SecretWord}\n\n" + $"Please confirm the account by clicking this link: {link}")); }