public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? this.Url.Content("~/"); this.ExternalLogins = (await this.signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); bool genderIsValid = this.Genders.Contains(this.Input.Gender); if (this.ModelState.IsValid && genderIsValid) { var user = new SchoolAppUser { UserName = this.Input.Email, Email = this.Input.Email, FirstName = this.Input.FirstName, LastName = this.Input.LastName, BirthDate = this.Input.BirthDate, Gender = this.Input.Gender, PhoneNumber = this.Input.PhoneNumber }; var result = await this.userManager.CreateAsync(user, this.Input.Password); if (result.Succeeded) { this.logger.LogInformation("User created a new account with password."); var code = await this.userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = this.Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.Id, code = code }, protocol: this.Request.Scheme); await this.emailSender.SendEmailAsync(this.Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); if (this.userManager.Options.SignIn.RequireConfirmedAccount) { return(this.RedirectToPage("RegisterConfirmation", new { email = this.Input.Email })); } else { await this.signInManager.SignInAsync(user, isPersistent : false); return(this.LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { this.ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(this.Page()); }
private async Task LoadAsync(SchoolAppUser user) { var email = await _userManager.GetEmailAsync(user); Email = email; Input = new InputModel { NewEmail = email, }; IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user); }
private async Task LoadAsync(SchoolAppUser user) { var userName = await _userManager.GetUserNameAsync(user); var phoneNumber = await _userManager.GetPhoneNumberAsync(user); var pictureUrl = user.ProfilePicture; Username = userName; Input = new InputModel { PhoneNumber = phoneNumber, ProfilePicture = pictureUrl, }; }