public async Task <IActionResult> OnPostAsync(string returnUrl = null) { var reCAPTCAResult = await _recaptchaService.VerifyResponse(Request.Form["g-recaptcha-response"].ToString()); if (!reCAPTCAResult) { ModelState.AddModelError(string.Empty, "reCAPTCHA failed"); } ReturnUrl = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = Input.Email, Email = Input.Email, FirstName = Input.FirstName, LastName = Input.LastName, IsHomeless = Input.IsHomeless, Address = Input.Address }; var result = await _userManager.CreateAsync(user, Input.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(Input.Email, callbackUrl); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(Url.GetLocalUrl(returnUrl))); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }