public ActionResult LoginCallBack() { AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("LoginCallBack")); if (result.IsSuccessful) { if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: true)) { return RedirectToAction("Index", "Home"); } else { string loginData = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId); ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(result.Provider).DisplayName; FilmTroveContext ftc = (FilmTroveContext)HttpContext.Items["ftcontext"]; UserProfile user = ftc.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == result.ProviderUserId.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table UserProfile prof = new UserProfile() { UserName = result.ProviderUserId, Provider = result.Provider, NetflixAccount = new NetflixAccount() }; if (result.UserName.Contains("@")) prof.Email = result.UserName; else prof.Name = result.UserName; UserProfile up = ftc.UserProfiles.Add(prof); ftc.Lists.Add(new UserList() { ListName = "My Collection", Owner = up }); ftc.SaveChanges(); String provider; String providerUserId; OAuthWebSecurity.TryDeserializeProviderUserId(loginData, out provider, out providerUserId); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, result.ProviderUserId); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); } else { //need to handle some error ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } return RedirectToAction("Index", "Home"); }
public UserUpdate(UserProfile up) { if (up.UserName.Contains("@")) Email = up.UserName; else Email = up.Email; Name = up.Name; }