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()); }
public async Task <IActionResult> ExternalRegisterUser([FromBody] RegisterExternalUserInputModel inputModel) { var info = await _signInManager.GetExternalLoginInfoAsync(); if (info == null) { return(Unauthorized("Error loading external login information.")); } var inputUser = inputModel.User; DateOfBirthValidationResult dateOfBirthValidationResult = DateOfBirth.IsValid( inputUser.Year.Value, inputUser.Month.Value, inputUser.Day.Value); if (!dateOfBirthValidationResult.IsValid) { return(BadRequest(dateOfBirthValidationResult.ErrorMessage)); } var user = new ApplicationUser { UserName = inputUser.UserName, Email = info.Principal.FindFirstValue(ClaimTypes.Email), EmailConfirmed = false, NewsletterSubscribed = inputUser.NewsletterSubscribed }; var utcDateOfBirth = new DateTime(inputUser.Year.Value, inputUser.Month.Value, inputUser.Day.Value); var result = await _registrationHandler.Value.RegisterUserAsync(user, null, utcDateOfBirth); if (!result.Succeeded) { var errors = result.Errors.ToDictionary(x => x.Code, x => x.Description); return(NotFound(errors)); } result = await _userManager.AddLoginAsync(user, info); if (!result.Succeeded) { var errors = result.Errors.ToDictionary(x => x.Code, x => x.Description); return(NotFound(errors)); } _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider); await _signInManager.SignInAsync(user, isPersistent : true, info.LoginProvider); await _accountMessageBroker.SendMessage(new RegisteredServiceBusMessage { AccountId = user.AccountId, CreyTicket = inputModel.CreyTicket }); await _registrationHandler.Value.AfterRegistrationAsync(user, utcDateOfBirth, Url, inputModel.CreyTicket, inputUser.AvatarId); return(Ok()); }
public async Task <IActionResult> RegisterUser([FromBody] RegisterUserInputModel inputModel) { _registrationHandler.Value.BeforeRegistration(inputModel.CreyTicket); var inputUser = inputModel.User; DateOfBirthValidationResult dateOfBirthValidationResult = DateOfBirth.IsValid( inputUser.Year.Value, inputUser.Month.Value, inputUser.Day.Value); if (!dateOfBirthValidationResult.IsValid) { return(BadRequest(dateOfBirthValidationResult.ErrorMessage)); } var user = new ApplicationUser { UserName = inputUser.UserName, Email = inputUser.Email, EmailConfirmed = false, NewsletterSubscribed = inputUser.NewsletterSubscribed, }; var utcDateOfBirth = new DateTime(inputUser.Year.Value, inputUser.Month.Value, inputUser.Day.Value); var result = await _registrationHandler.Value.RegisterUserAsync(user, inputUser.Password, utcDateOfBirth); if (!result.Succeeded) { return(BadRequest(result.Errors)); } _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 = inputModel.CreyTicket }); await _registrationHandler.Value.AfterRegistrationAsync(user, utcDateOfBirth, Url, inputModel.CreyTicket, inputUser.AvatarId); return(Ok()); }
public async Task <IActionResult> OnPostAsync(string provider, string creyTicket, string returnUrl = null) { ReturnUrl = returnUrl; CreyTicket = creyTicket; var info = await _signInManager.GetExternalLoginInfoAsync(); if (info == null) { ErrorMessage = "Error loading external login information."; return(RedirectToPage("./Login", new { ReturnUrl = returnUrl })); } LoginProvider = info.LoginProvider; Email = info.Principal.FindFirstValue(ClaimTypes.Email); ReturnUrl = returnUrl; if (ModelState.IsValid) { DateOfBirthValidationResult dateOfBirthValidationResult = DateOfBirth.IsValid(Input.Year.Value, Input.Month.Value, Input.Day.Value); if (!dateOfBirthValidationResult.IsValid) { BirthDateErrorMessage = dateOfBirthValidationResult.ErrorMessage; return(Page()); } var user = new ApplicationUser { UserName = Input.UserName, Email = 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, null, utcDateOfBirth); if (result.Succeeded) { result = await _userManager.AddLoginAsync(user, info); if (result.Succeeded) { _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider); await _signInManager.SignInAsync(user, isPersistent : true, info.LoginProvider); 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); } } return(Page()); }