public async Task <ExternalLoginInfo> GetExternalLoginConfirmationAsync(UserExternalLoginViewModel model, string returnUrl = null) { var info = await signInManager.GetExternalLoginInfoAsync(); var facebookData = await this.facebookService.GetFacebookInfoAsync(); byte[] pictureInBytes = Encoding.ASCII.GetBytes(facebookData[2]); var user = new FastFoodUser { UserName = model.Email, Email = model.Email, FirstName = facebookData[0], LastName = facebookData[1], Picture = pictureInBytes }; var result = await userManager.CreateAsync(user); await this.userManager.AddToRoleAsync(user, StringConstants.UserRole); if (result.Succeeded) { result = await userManager.AddLoginAsync(user, info); if (result.Succeeded) { await signInManager.SignInAsync(user, isPersistent : false); } } return(info); }
public async Task <IActionResult> ExternalLoginConfirmation(UserExternalLoginViewModel model, string returnUrl = null) { if (ModelState.IsValid) { var info = await this.userService.GetExternalLoginConfirmationAsync(model, returnUrl); this.logger.LogInformation(string.Format(LogMessages.UserCreatedExternalLogin, info.LoginProvider)); return(Redirect(Routes.Home)); } return(this.View(model)); }