public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { Name = model.Name.Trim(), UserName = model.Email.Trim(), Email = model.Email.Trim(), Language = model.Language, ToDoNotificationsEnabled = false, CookingNotificationsEnabled = false, ImperialSystem = false, ImageUri = _cdnService.GetDefaultProfileImageUri(), DateRegistered = DateTime.UtcNow }; IdentityResult result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { string token = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action("confirm-email", "Account", new { userId = user.Id, token, returnUrl }, HttpContext.Request.Scheme); await _emailTemplateService.EnqueueRegisterConfirmationEmailAsync(user.Name, user.Email, new Uri(callbackUrl), model.Language); // Notify admin _ = _emailTemplateService.EnqueueNewRegistrationEmailAsync(user.Name, user.Email); SetLanguageCookie(model.Language); return(RedirectToAction(nameof(AccountController.Login), new { alert = GenerateLoginAlertFromRegistrationEmail(user.Email) })); } AddIdentityErrors(result, nameof(AccountController.Register)); } return(View(model)); }