public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)//THERE WE WILL GO IF U DONT HAVE AN ACCOUNT!!! { //WAS UNCOMMENTED BEFORE!!! //if (User.Identity.IsAuthenticated) //{ // return RedirectToAction("IndexEvents", "Event"); //} if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return(View("ExternalLoginFailure")); } var user = new Korgie.Models.ApplicationUser { UserName = model.Name, Email = model.Email }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); HttpCookie cookie = Request.Cookies["Preferences"]; if (cookie == null) { cookie = new HttpCookie("Preferences"); } cookie["Email"] = model.Email; Response.Cookies.Add(cookie); using (var conn = new SqlConnection("Server=tcp:ivqgu1eln8.database.windows.net,1433;Database=korgie_db_2015-12-13T23-44Z;User ID=frankiel@ivqgu1eln8;Password=Helloworld123;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;")) { var cmd = new SqlCommand(@"INSERT INTO Users VALUES (@Email,@Name,@Email,'','','','Sport btn--blue #2196F3','Work btn--red #F44336','Study btn--green #4CAF50','Additional btn--yellow #FFEB3B','Rest btn--purple #9C27B0')", conn); cmd.Parameters.AddWithValue("@Email", user.Email); cmd.Parameters.AddWithValue("@Name", user.UserName); conn.Open(); cmd.ExecuteNonQuery(); bool resultInvite = false; var cmd2 = new SqlCommand(@"SELECT * FROM Invites WHERE InvitedEmailUser=@Email", conn); cmd2.Parameters.AddWithValue("@Email", user.Email); string usertoadd = ""; using (SqlDataReader dr = cmd2.ExecuteReader(System.Data.CommandBehavior.CloseConnection)) { while (dr.Read()) { usertoadd = dr.GetString(1); resultInvite = true; } } if (resultInvite) { conn.Open(); var cmd4 = new SqlCommand(@"DELETE FROM Invites WHERE InvitedEmailUser=@Email", conn); cmd4.Parameters.AddWithValue("@Email", usertoadd); cmd4.ExecuteNonQuery(); var cmd3 = new SqlCommand(@"INSERT INTO UserContacts VALUES (@PrimaryUser,@Invited,'Sent')", conn); cmd3.Parameters.AddWithValue("@PrimaryUser", usertoadd); cmd3.Parameters.AddWithValue("@Invited", Request.Cookies["Preferences"]["Email"]); cmd3.ExecuteNonQuery(); } } return(RedirectToAction("Index", "Event")); //RedirectToLocal(returnUrl) //THERE WE WILL GO AFTER PRESSING BUTTON REGISTER IF U DIDNT HAVE AN ACC!!! } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return(View(model)); //parameter was 'model' }
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)//THERE WE WILL GO IF U DONT HAVE AN ACCOUNT!!! { //WAS UNCOMMENTED BEFORE!!! //if (User.Identity.IsAuthenticated) //{ // return RedirectToAction("IndexEvents", "Event"); //} if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return View("ExternalLoginFailure"); } var user = new Korgie.Models.ApplicationUser { UserName = model.Name, Email = model.Email }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); HttpCookie cookie = Request.Cookies["Preferences"]; if (cookie == null) { cookie = new HttpCookie("Preferences"); } cookie["Email"] = model.Email; Response.Cookies.Add(cookie); return RedirectToAction("IndexEvents", "Event"); //RedirectToLocal(returnUrl) //THERE WE WILL GO AFTER PRESSING BUTTON REGISTER IF U DIDNT HAVE AN ACC!!! } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return View(model); //parameter was 'model' }
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)//THERE WE WILL GO IF U DONT HAVE AN ACCOUNT!!! { //WAS UNCOMMENTED BEFORE!!! //if (User.Identity.IsAuthenticated) //{ // return RedirectToAction("IndexEvents", "Event"); //} if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return View("ExternalLoginFailure"); } var user = new Korgie.Models.ApplicationUser { UserName = model.Name, Email = model.Email}; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); HttpCookie cookie = Request.Cookies["Preferences"]; if (cookie == null) { cookie = new HttpCookie("Preferences"); } cookie["Email"] = model.Email; Response.Cookies.Add(cookie); using (var conn = new SqlConnection("Server=tcp:ivqgu1eln8.database.windows.net,1433;Database=korgie_db_2015-12-13T23-44Z;User ID=frankiel@ivqgu1eln8;Password=Helloworld123;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;")) { var cmd = new SqlCommand(@"INSERT INTO Users VALUES (@Email,@Name,@Email,'','','','Sport btn--blue #2196F3','Work btn--red #F44336','Study btn--green #4CAF50','Additional btn--yellow #FFEB3B','Rest btn--purple #9C27B0')", conn); cmd.Parameters.AddWithValue("@Email", user.Email); cmd.Parameters.AddWithValue("@Name", user.UserName); conn.Open(); cmd.ExecuteNonQuery(); bool resultInvite = false; var cmd2 = new SqlCommand(@"SELECT * FROM Invites WHERE InvitedEmailUser=@Email", conn); cmd2.Parameters.AddWithValue("@Email", user.Email); string usertoadd = ""; using (SqlDataReader dr = cmd2.ExecuteReader(System.Data.CommandBehavior.CloseConnection)) { while (dr.Read()) { usertoadd = dr.GetString(1); resultInvite = true; } } if (resultInvite) { conn.Open(); var cmd4 = new SqlCommand(@"DELETE FROM Invites WHERE InvitedEmailUser=@Email", conn); cmd4.Parameters.AddWithValue("@Email", usertoadd); cmd4.ExecuteNonQuery(); var cmd3 = new SqlCommand(@"INSERT INTO UserContacts VALUES (@PrimaryUser,@Invited,'Sent')", conn); cmd3.Parameters.AddWithValue("@PrimaryUser", usertoadd); cmd3.Parameters.AddWithValue("@Invited", Request.Cookies["Preferences"]["Email"]); cmd3.ExecuteNonQuery(); } } return RedirectToAction("Index", "Event"); //RedirectToLocal(returnUrl) //THERE WE WILL GO AFTER PRESSING BUTTON REGISTER IF U DIDNT HAVE AN ACC!!! } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return View(model); //parameter was 'model' }