/// <summary> /// Manage user profile like adding or deleting user from databse or updating user email or role in the database. /// </summary> public static void RequestedAction() { DataService.AccessService dataService = new DataService.AccessService(); var file = new StreamReader(File.OpenRead(@"c:\Test.csv")); while (!file.EndOfStream) { var EachLine = file.ReadLine(); var valuesOfLine = EachLine.Split(','); string userEmail = valuesOfLine[0]; int role = int.Parse(valuesOfLine[1]); string Action = valuesOfLine[2]; //string NewEmail = valuesOfLine[3]; if (Action == "add") { dataService.AddUser(userEmail, role); } else if (Action == "delete") { dataService.DeleteUser(userEmail); } else if (Action == "updateRole") { dataService.UpdateUserRole(userEmail, role); } else if (Action == "updateEmail") { string NewEmail = valuesOfLine[3]; dataService.UpdateUserEmail(userEmail, NewEmail); } } }
//GET: /Account/IsLogged /// public string IsLogin() { try { DataService.AccessService dataService = new DataService.AccessService(); var userExists = dataService.IsUserAuthorized(this.Session["username"].ToString()); if (userExists) { return(JsonConvert.SerializeObject(this.Session["username"].ToString())); } else { return(JsonConvert.SerializeObject("NOT AUTHORIZED")); } } catch (Exception) { return(JsonConvert.SerializeObject(null)); } }
//[AllowAnonymous] //public ActionResult ExternalLoginCallbackRedirect(string returnUrl) //{ // return RedirectPermanent("/Account/ExternalLoginCallback"); //} // GET: /Account/ExternalLoginCallback // [BasicAuthentication] //[AllowAnonymous] //public async bool IsAuthorizedUser() //{ // var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); // var email = loginInfo.Email; // this.Session["username"] = loginInfo.Email; // DataService.AccessService dataService = new DataService.AccessService(); // var userExists = dataService.IsUserAuthorized(email); // if (userExists) // { // return true; // } // else // return false; //} /// <summary> /// This method is invoked when user is authenticated that is when the user login with there google account. /// and in this method the authrization is done to see if the user is authorised user or not. /// </summary> /// <param name="returnUrl"></param> /// <returns> returns authorized users to index.html page</returns> public async Task <ActionResult> ExternalLoginCallback(string returnUrl) { var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); if (loginInfo == null) { return(Redirect("/dashboard/index.html")); //return RedirectToAction("Login"); } // Sign in the user with this external login provider if the user already has a login //var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false); var email = loginInfo.Email; this.Session["username"] = loginInfo.Email; DataService.AccessService dataService = new DataService.AccessService(); var userExists = dataService.IsUserAuthorized(email); if (userExists) { //this.Session.Contents.Remove("Salt"); //this.Session.Contents.RemoveAll(); //this.Session.Clear(); //this.Session.Abandon(); //this.Session.RemoveAll(); //this.Session["P"] = "P"; return(Redirect("/dashboard/index.html")); } else { return(Redirect("/dashboard/index.html")); } //switch (result) // { // case SignInStatus.Success: // // var email = loginInfo.Email; // DataService.AccessService dataService = new DataService.AccessService(); // var userExists = dataService.IsUserAuthorized(email); // if (userExists) // { // return View("Success");// or RedirectToAction("Success"); // } // else // { // return View("UnauthAccess"); // } // //return RedirectToLocal(returnUrl); // case SignInStatus.LockedOut: // return View("Lockout"); // case SignInStatus.RequiresVerification: // return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false }); // case SignInStatus.Failure: // default: // // If the user does not have an account, then prompt the user to create an account // ViewBag.ReturnUrl = returnUrl; // ViewBag.LoginProvider = loginInfo.Login.LoginProvider; // return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email }); // } }
//[AllowAnonymous] //public ActionResult ExternalLoginCallbackRedirect(string returnUrl) //{ // return RedirectPermanent("/Account/ExternalLoginCallback"); //} // GET: /Account/ExternalLoginCallback // [BasicAuthentication] //[AllowAnonymous] //public async bool IsAuthorizedUser() //{ // var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); // var email = loginInfo.Email; // this.Session["username"] = loginInfo.Email; // DataService.AccessService dataService = new DataService.AccessService(); // var userExists = dataService.IsUserAuthorized(email); // if (userExists) // { // return true; // } // else // return false; //} /// <summary> /// This method is invoked when user is authenticated that is when the user login with there google account. /// and in this method the authrization is done to see if the user is authorised user or not. /// </summary> /// <param name="returnUrl"></param> /// <returns> returns authorized users to index.html page</returns> public async Task<ActionResult> ExternalLoginCallback(string returnUrl) { var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); if (loginInfo == null) { return Redirect("/dashboard/index.html"); //return RedirectToAction("Login"); } // Sign in the user with this external login provider if the user already has a login //var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false); var email = loginInfo.Email; this.Session["username"] = loginInfo.Email; DataService.AccessService dataService = new DataService.AccessService(); var userExists = dataService.IsUserAuthorized(email); if (userExists) { //this.Session.Contents.Remove("Salt"); //this.Session.Contents.RemoveAll(); //this.Session.Clear(); //this.Session.Abandon(); //this.Session.RemoveAll(); //this.Session["P"] = "P"; return Redirect("/dashboard/index.html"); } else { return Redirect("/dashboard/index.html"); } //switch (result) // { // case SignInStatus.Success: // // var email = loginInfo.Email; // DataService.AccessService dataService = new DataService.AccessService(); // var userExists = dataService.IsUserAuthorized(email); // if (userExists) // { // return View("Success");// or RedirectToAction("Success"); // } // else // { // return View("UnauthAccess"); // } // //return RedirectToLocal(returnUrl); // case SignInStatus.LockedOut: // return View("Lockout"); // case SignInStatus.RequiresVerification: // return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false }); // case SignInStatus.Failure: // default: // // If the user does not have an account, then prompt the user to create an account // ViewBag.ReturnUrl = returnUrl; // ViewBag.LoginProvider = loginInfo.Login.LoginProvider; // return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email }); // } }
//GET: /Account/IsLogged /// public string IsLogin() { try { DataService.AccessService dataService = new DataService.AccessService(); var userExists = dataService.IsUserAuthorized(this.Session["username"].ToString()); if (userExists) { return JsonConvert.SerializeObject(this.Session["username"].ToString()); } else { return JsonConvert.SerializeObject("NOT AUTHORIZED"); } } catch (Exception) { return JsonConvert.SerializeObject(null); } }