public ActionResult ExternalLoginCallback(string returnUrl) { Debug.Write("ExternalLoginCallback started\n"); AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl })); //kdyz se prihlaseni nezdari if (!result.IsSuccessful) { return RedirectToAction("ExternalLoginFailure"); } //if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: false)) //{ // Debug.Write("ExternalLoginCallback auth login\n"); // return RedirectToLocal(returnUrl); //} //if (User.Identity.IsAuthenticated) //{ // // If the current user is logged in add the new account // Debug.Write("ExternalLoginCallback user identity is authenticated\n"); // OAuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId, User.Identity.Name); // return RedirectToLocal(returnUrl); //} else { PFTContext db = new PFTContext(); Trainee trainee = db.Trainees.Where(b => b.email == result.UserName).FirstOrDefault(); if (trainee == null) { return View("NoAccount"); } Response.Cookies["Authorized"].Value = "true"; Response.Cookies["Authorized"].Expires = DateTime.Now.AddHours(1); return RedirectToAction("Details", "Trainee", trainee); //// User is new, ask for their desired membership name //string loginData = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId); //ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(result.Provider).DisplayName; //ViewBag.ReturnUrl = returnUrl; //using (SqlConnection connection = new SqlConnection("Data Source=MASTAH-PC;Initial Catalog=PFTDB;Integrated Security=True")) //{ // SqlCommand command = new SqlCommand(); //connection.Open(); //command.Connection = connection; //command.Parameters.AddWithValue("@email", result.UserName); //command.CommandText = "SELECT * FROM Trainee WHERE email = @email"; //SqlDataReader trainee = command.ExecuteReader(); // Debug.Write(result.UserName+" select sestaven\n"); // // Check if user already exists // if (!trainee.HasRows) // { // Debug.Write("Pokus o zobrazeni noaccount\n"); // connection.Close(); // return View("NoAccount"); // } // else // { // Debug.Write("Uzivatel v DB nalezen\n"); // while (trainee.Read()) // { // ViewBag.Id = trainee["Id"]; // ViewBag.Name = trainee["name"]; // ViewBag.Birth = trainee["birth"]; // ViewBag.Gender = trainee["gender"]; // ViewBag.Experience = trainee["experience"]; // ViewBag.Goal = trainee["goal"]; // } // connection.Close(); // return View("Loggedin"); // } //} //Debug.Write("ExternalLoginCallback else sranec\n"); //return View("ExternalLoginConfirmation", new RegisterExternalLoginModel { UserName = result.UserName, ExternalLoginData = loginData }); } }