private async Task LoadAsync(string id) { UserID = UserManager.GetUserId(User); if (UserID == id) { ProfileOwner = true; } InvolverUser = await Context.Users.Where(u => u.Id == id).FirstOrDefaultAsync(); Profile = await Context.Profiles .Include(p => p.Follows) .Where(p => p.ProfileID == id) .FirstOrDefaultAsync(); if (Profile != null) { Follow ExistingFollow = Profile.Follows .Where(f => f.FollowerID == UserID) .FirstOrDefault(); if (ExistingFollow != null) { Followed = true; } else { Followed = false; } } }
private async Task LoadAsync(InvolverUser user) { var email = await _userManager.GetEmailAsync(user); Email = email; Input = new InputModel { NewEmail = email, }; IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user); }
private async Task LoadAsync(InvolverUser user) { var userName = await _userManager.GetUserNameAsync(user); var phoneNumber = await _userManager.GetPhoneNumberAsync(user); var bankAccount = _userManager.GetUserAsync(User).Result.BankAccount; Input = new InputModel { UserName = userName, PhoneNumber = phoneNumber, BankAccount = bankAccount }; }
private async Task LoadSharedKeyAndQrCodeUriAsync(InvolverUser 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> OnPostConfirmationAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); // Get the information about the user from the external login provider var info = await _signInManager.GetExternalLoginInfoAsync(); if (info == null) { ErrorMessage = "Error loading external login information during confirmation."; return(RedirectToPage("./Login", new { ReturnUrl = returnUrl })); } if (ModelState.IsValid) { //只取@前字串的作為用戶名 string pattern = @"@\S+$"; string UserNameWithoutAddress = Regex.Replace(Input.Email, pattern, String.Empty); var user = new InvolverUser { UserName = UserNameWithoutAddress, Email = Input.Email }; var result = await _userManager.CreateAsync(user); 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 : false); var userId = await _userManager.GetUserIdAsync(user); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = userId, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "確認你的Email", $"請<a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>點擊此連結</a>以確認你的Email"); // If account confirmation is required, we need to show the link if we don't have a real email sender if (_userManager.Options.SignIn.RequireConfirmedAccount) { return(RedirectToPage("./RegisterConfirmation", new { Email = Input.Email })); } return(LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } LoginProvider = info.LoginProvider; ReturnUrl = returnUrl; return(Page()); }