public async Task <IActionResult> OnGet() { var userName = Guid.NewGuid().ToString(); var password = Guid.NewGuid().ToString(); password = password.Substring(0, 5).ToUpper() + password.Substring(5); var characterName = "Soul" + new Random().Next(0, 9999999).ToString(); while (DataService.IsCharacterNameTaken(characterName)) { characterName = "Soul" + new Random().Next(0, 9999999).ToString(); } if (ModelState.IsValid) { var user = new AfterUser { UserName = userName, IsTemporary = true, Characters = new List <PlayerCharacter>() { new PlayerCharacter() { Name = characterName } } }; var result = await UserManager.CreateAsync(user, password); if (result.Succeeded) { Logger.LogInformation("Temporary user created."); await SignInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect($"/play?character={characterName}")); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(LocalRedirect("/")); }
private async Task LoadSharedKeyAndQrCodeUriAsync(AfterUser user) { // Load the authenticator key & QR code URI to display on the form var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user); if (string.IsNullOrEmpty(unformattedKey)) { await _userManager.ResetAuthenticatorKeyAsync(user); unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user); } SharedKey = FormatKey(unformattedKey); var email = await _userManager.GetEmailAsync(user); AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new AfterUser { UserName = Input.Username, Email = Input.Email }; 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.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }