public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Manage")); } if (ModelState.IsValid) { FFFUser user = new FFFUser(model.UserName); // Get the information about the user from the external login provider var result = await IdentityManager.Authentication.CreateAndSignInExternalUserAsync(AuthenticationManager, user, CancellationToken.None); if (result.Success) { db.SaveChanges(); this.Account = user.Account; db.SaveChanges(); this.Account.User = user; db.SaveChanges(); this.Account.ShoppingCart = new ShoppingCart(); db.SaveChanges(); Email Email = new FFF.Models.ContactSystem.Email(model.Email); this.Account.Emails.Add(Email); this.Account.DefaultEmail = Email; this.Account.FirstName = model.FirstName; this.Account.LastName = model.LastName; this.Account.Gender = db.Genders.First(c => c.RID == model.GenderID); db.SaveChanges(); //FormsAuthentication.SetAuthCookie( model.UserName, false ); if (returnUrl == Url.Action("Index", "Store")) { return(RedirectToAction("Index", "Account")); } else { return(RedirectToLocal(returnUrl)); } } else { return(View("ExternalLoginFailure")); } } ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return RedirectToAction("Manage"); } if (ModelState.IsValid) { FFFUser user = new FFFUser( model.UserName ); // Get the information about the user from the external login provider var result = await IdentityManager.Authentication.CreateAndSignInExternalUserAsync( AuthenticationManager, user , CancellationToken.None ); if ( result.Success ) { db.SaveChanges(); this.Account = user.Account; db.SaveChanges(); this.Account.User = user; db.SaveChanges(); this.Account.ShoppingCart = new ShoppingCart(); db.SaveChanges(); Email Email = new FFF.Models.ContactSystem.Email(model.Email); this.Account.Emails.Add( Email ); this.Account.DefaultEmail = Email; this.Account.FirstName = model.FirstName; this.Account.LastName = model.LastName; this.Account.Gender = db.Genders.First(c => c.RID == model.GenderID); db.SaveChanges(); //FormsAuthentication.SetAuthCookie( model.UserName, false ); if(returnUrl == Url.Action("Index", "Store")) return RedirectToAction("Index", "Account"); else return RedirectToLocal(returnUrl); } else { return View("ExternalLoginFailure"); } } ViewBag.ReturnUrl = returnUrl; return View(model); }