public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return RedirectToAction("Manage"); } if (!model.TermsAndConditions) { ModelState.AddModelError("TermsAndConditions", "You must agree to the terms and conditions to register."); } if (ModelState.IsValid) { // Insert a new user into the database using (UsersContext db = new UsersContext()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); db.SaveChanges(); var artist = new Artist { UserName = model.UserName, UserType = DomainModel.Entities.User.UserTypeList.Artist, TermsAndConditionsAccepted = model.TermsAndConditions, }; var trmwebservice = new WebService.WCFWebServiceJson(); if (trmwebservice.RegisterArtistSocial(artist, provider, providerUserId)) { OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return RedirectToAction("RegisterSuccess", "Account"); } else { ModelState.AddModelError("ArtistRegistrationError", "There was an issue registering you. If the problemt persists, please contact us at [email protected]"); } } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return View(model); }