public async Task <IActionResult> OnPostAsync(string creyTicket, string returnUrl = null) { ReturnUrl = returnUrl; CreyTicket = creyTicket; ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); _registrationHandler.Value.BeforeRegistration(CreyTicket); if (ModelState.IsValid) { DateOfBirthValidationResult dateOfBirthValidationResult = DateOfBirth.IsValid(Input.Year.Value, Input.Month.Value, Input.Day.Value); if (!dateOfBirthValidationResult.IsValid) { BirthDateErrorMessage = dateOfBirthValidationResult.ErrorMessage; return(Page()); } bool isReCaptchaValid = await _reCaptcha.IsResponseValid(Request.Form["g-recaptcha-response"]); if (!isReCaptchaValid) { ModelState.AddModelError(string.Empty, "Captcha validation unsuccessful."); return(Page()); } var user = new ApplicationUser { UserName = Input.UserName, Email = Input.Email, EmailConfirmed = false, NewsletterSubscribed = Input.NewsletterSubscribed, }; var utcDateOfBirth = new DateTime(Input.Year.Value, Input.Month.Value, Input.Day.Value); var result = await _registrationHandler.Value.RegisterUserAsync(user, Input.Password, utcDateOfBirth); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); await _signInManager.SignInAsync(user, isPersistent : true, CredentialType.LoginPage.ToString()); await _accountMessageBroker.SendMessage(new RegisteredServiceBusMessage { AccountId = user.AccountId, CreyTicket = CreyTicket }); await _registrationHandler.Value.AfterRegistrationAsync(user, utcDateOfBirth, Url, CreyTicket, Input.AvatarId); return(RedirectToPage("./Redirect", new { redirectUrl = returnUrl })); } foreach (var error in result.Errors) { ModelState.AddModelError(error.Code.TranslateModelErrorCode(), error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }