private async Task LoadAsync(CotacolUser user) { var userName = await _userManager.GetUserNameAsync(user); var phoneNumber = await _userManager.GetPhoneNumberAsync(user); Username = userName; Input = new InputModel { PhoneNumber = phoneNumber }; }
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 User.GetLoginInfo(_signInManager); if (ModelState.IsValid) { var user = new CotacolUser { Id = info.GetUserId(), UserName = Input.UserName, Email = Input.Email, FirstName = info.Principal.GetClaim(IdentityExtensions.FirstNameClaim), LastName = info.Principal.GetClaim(IdentityExtensions.LastNameClaim), ProfilePicture = info.Principal.GetClaim(IdentityExtensions.ProfilePictureClaim) }; // register user here if (_cotacolClient != null) { _logger.LogTrace($"Setting up user {info.Principal.GetUserId()} on Cotacol API"); await _cotacolClient.SetupUserAsync(new UserSetupRequest { CotacolHunter = true, UserId = user.Id, UserName = user.UserName, FullName = $"{user.FirstName} {user.LastName}", EmailAddress = user.Email, PremiumUser = false, StravaRefreshToken = info.AuthenticationTokens .FirstOrDefault(token => token.Name.Equals("refresh_token"))?.Value }); } 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); var userId = await _userManager.GetUserIdAsync(user); //TODO : email verification // 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, "Confirm your email", // $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); // // // 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}); // } await _signInManager.SignInAsync(user, isPersistent : true, info.LoginProvider); _logger.LogInformation( $"User {user.UserName} sign in result: {_signInManager.IsSignedIn(info.Principal)}"); return(LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } ProviderDisplayName = "Strava"; ReturnUrl = returnUrl; return(Page()); }