public ActionResult Index() { //String dataPermissions = Session["Permissions"].ToString(); //String dataPermissionsClient = Session["PermissionsClient"].ToString(); //bool access = false; //bool accessClient = false; // access = getpermissions("users", "r"); //access = validatepermissions.getpermissions("employee", "r", dataPermissions); //accessClient = validatepermissions.getpermissions("employee", "r", dataPermissionsClient); //if (access == true) && accessClient == true) if (true) { /////bind empli try { String profileOptions = ""; List <BsonDocument> profileList = employeeprofileTable.getRows(); //getting all the profiles profileOptions += "<option value='null' selected> Elija una opción</option>"; foreach (BsonDocument document in profileList) //for each profile we create an option element with id as value and the name as the text { profileOptions += "<option value='" + document.GetElement("_id").Value + "'"; //setting the id as the value profileOptions += ">" + document.GetElement("name").Value + "</option>"; //setting the text as the name } ViewData["profileList"] = new HtmlString(profileOptions); } catch (Exception ex) { ViewData["profileList"] = null; } //Detects if the user is an Admin try { JObject userdata = JsonConvert.DeserializeObject <JObject>(userTable.GetRow(this.Session["_id"].ToString())); JObject userprofile = JsonConvert.DeserializeObject <JObject>(profileTable.GetRow(userdata["profileId"].ToString())); if (userprofile["name"].ToString() == "Administrador de sistema") { ViewData["signalMasive"] = true; } else { ViewData["signalMasive"] = false; } } catch (Exception ex) { ViewData["signalMasive"] = false; } loadAreas(); return(View()); } else { return(Redirect("~/Home")); } }
public ActionResult getInventoryTable() { string userid = Session["_id"].ToString(); String inventoryArray = _inventoryTable.Get("Creator", userid, "dateStart"); JArray inventory = JsonConvert.DeserializeObject <JArray>(inventoryArray); foreach (JObject rowString in inventory) { JToken userList = rowString["userList"]; string cant = userList.Count().ToString(); if (cant == "0") { cant = "Todos"; //All Users } rowString["cant"] = cant; try { String locationString = _locationTable.GetRow(rowString["location"].ToString()); JObject location = JsonConvert.DeserializeObject <JObject>(locationString); rowString["locationName"] = location["name"]; } catch (Exception e) { } try { String profileString = _profileTable.GetRow(rowString["profile"].ToString()); JObject profile = JsonConvert.DeserializeObject <JObject>(profileString); rowString["profileName"] = profile["name"]; } catch (Exception e) { } try { String hardwareString = _hardwareTable.GetHardware(rowString["hardware"].ToString()); JArray hardware = JsonConvert.DeserializeObject <JArray>(hardwareString); rowString["hardwareName"] = hardware[0]["name"]; } catch (Exception e) { } } return(View(inventory)); }
/// <summary> /// Check if username and password is valid, if it is, sets sessions and formauth to true /// </summary> /// <param name="username">The user name</param> /// <param name="password">The User password</param> /// <returns>Index View if valid user, Login view if invalid user</returns> /// <author>Galaviz Alejos Luis Angel</author> public ActionResult Login(string username, string password) { if (username == "" || password == "") { this.Redirect("/Login"); } //Check the user on the database //usertable = new UserTable(); BsonDocument doc = usertable.Login(username, password); ProfileTable profiletable = new ProfileTable(); //If the return is null, is an invalid user if (doc != null) { //User Password time validation if (doc["_id"].AsObjectId.ToString() != "52e95ab907719e0d40637d96") { JObject userInformation = JsonConvert.DeserializeObject <JObject>(usertable.GetRow(doc["_id"].AsObjectId.ToString())); if (userInformation["lastChgPassword"] != null) { try { DateTime d1 = DateTime.ParseExact(userInformation["lastChgPassword"].ToString(), "dd/MM/yyyy HH:mm:ss", null); DateTime d2 = DateTime.Now; systemSettingsTable = new SystemSettingsTable(); JArray cantDays = JsonConvert.DeserializeObject <JArray>(systemSettingsTable.Get("name", "daysChangePassword")); string days = (from mov in cantDays select(string) mov["days"]).First().ToString(); TimeSpan time = d2 - d1; int NrOfDays = time.Days; if (int.Parse(days) <= NrOfDays) { ViewBag.Message = "Timeout"; ViewData["timeout"] = "Timeout"; List <string> backgrounds = Design.getBackgrounds(); return(View("Index", backgrounds)); } } catch (Exception ex) { ViewBag.Error = true; ViewBag.Message = ex.ToString(); ViewData["timeout"] = ex.ToString(); List <string> backgrounds = Design.getBackgrounds(); return(View("Index", backgrounds)); } } else { try { JObject user = JsonConvert.DeserializeObject <JObject>(usertable.GetRow(doc["_id"].AsObjectId.ToString())); user["lastChgPassword"] = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"); usertable.saveRow(JsonConvert.SerializeObject(user), user["_id"].ToString()); } catch (Exception ex) { // throw new Exception(ex.ToString()); //return Redirect("~/Home"); } //END - User Password time validation } } DataFileManager Filelimits; string filepath = "/App_Data/system.conf"; string absolutedpath = Server.MapPath(filepath); Filelimits = new DataFileManager(absolutedpath, "juanin"); if (!Filelimits.empty()) { //Set user name (to show on the upper right corner of the system) this.Session["LoggedUser"] = ""; try { this.Session["Semaphores"] = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"); HttpCookie aCookiesem = new HttpCookie("semaphores"); aCookiesem.Value = Session["Semaphores"].ToString(); aCookiesem.Expires = DateTime.Now.AddDays(10); Response.Cookies.Add(aCookiesem); } catch (Exception ex) { } this.Session["Username"] = ""; try { this.Session["Username"] = doc["name"].AsString; this.Session["LoggedUser"] += doc["name"].AsString; try { this.Session["LoggedUser"] += " " + doc["lastname"].AsString; } catch (Exception e) { /*Ignored*/ } } catch (Exception e) { /*Ignored*/ } //If needed for user transactions this.Session["_id"] = doc["_id"].AsObjectId; HttpCookie aCookie2 = new HttpCookie("_id2"); aCookie2.Value = doc["_id"].AsObjectId.ToString(); aCookie2.Expires = DateTime.Now.AddDays(10); Response.Cookies.Add(aCookie2); //Check if there exist the image extension registry on database, if it exist, sets the relative //path try { if (!string.IsNullOrEmpty(doc["imgext"].ToString())) { //Relative path to save images string relativepath = string.Format("\\Uploads\\Images\\{0}.{1}", Session["_id"].ToString(), doc["imgext"].ToString()); //Check if profile picture file exists on the server if (System.IO.File.Exists(Server.MapPath(relativepath))) { //if it exist, sets the profile picture url this.Session["ProfilePicture"] = Url.Content(relativepath); HttpCookie aCookie4 = new HttpCookie("_picture"); aCookie4.Value = Url.Content(relativepath); aCookie4.Expires = DateTime.Now.AddDays(10); Response.Cookies.Add(aCookie4); } else { //Set picture to default this.Session["ProfilePicture"] = null; } } } catch (Exception e) { /*Ignored*/ } string usuarioid = Session["_id"].ToString(); String profileid = usertable.getRowString(usuarioid); JObject rowArray = JsonConvert.DeserializeObject <JObject>(profileid); var jdatos = ""; if (rowArray["permissionsHTK"] != null) { string arraypermisos = rowArray["permissionsHTK"].ToString(); JObject allp = JsonConvert.DeserializeObject <JObject>(arraypermisos); jdatos = JsonConvert.SerializeObject(allp); this.Session["Permissions"] = jdatos.ToString(); } else { string idpro = rowArray["profileId"].ToString(); String profiles = profiletable.GetRow(idpro); JObject rowArraypro = JsonConvert.DeserializeObject <JObject>(profiles); string arraypermisos = rowArraypro["permissionsHTK"].ToString(); JObject allp = JsonConvert.DeserializeObject <JObject>(arraypermisos); jdatos = JsonConvert.SerializeObject(allp); this.Session["Permissions"] = jdatos.ToString(); } try { this.Session["PermissionsClient"] = Filelimits["scenario"]["modules"].ToString(); string filedata = Filelimits["scenario"]["modules"].ToString(); HttpCookie aCookiep = new HttpCookie("permissionsclient"); aCookiep.Value = Filelimits["scenario"]["modules"].ToString(); aCookiep.Expires = DateTime.Now.AddDays(10); Response.Cookies.Add(aCookiep); } catch (Exception ex) { this.Session["PermissionsClient"] = ""; } HttpCookie aCookie = new HttpCookie("permissions"); aCookie.Value = jdatos.ToString(); aCookie.Expires = DateTime.Now.AddDays(10); Response.Cookies.Add(aCookie); HttpCookie aCookie1 = new HttpCookie("_loggeduser"); aCookie1.Value = Session["LoggedUser"].ToString(); aCookie1.Expires = DateTime.Now.AddDays(10); Response.Cookies.Add(aCookie1); HttpCookie aCookie3 = new HttpCookie("_username"); aCookie3.Value = Session["Username"].ToString(); aCookie3.Expires = DateTime.Now.AddDays(10); Response.Cookies.Add(aCookie3); //Sets the login authorization FormsAuthentication.SetAuthCookie("User", false); TimeSpan time = FormsAuthentication.Timeout; // FormsAuthentication.Timeout.Subtract(time); //Redirect Index FormsAuthentication.Timeout.Subtract(time); /* TimeSpan time2= TimeSpan.Parse("00:04:00"); * FormsAuthentication.Timeout.Add(time2); * string horasuma2 = DateTime.Now.ToString("HH:mm:ss"); * TimeSpan timenow = TimeSpan.Parse(horasuma2); * int total = time2.Minutes - timenow.Minutes;*/ return(Redirect("~/Home")); } else { ViewBag.Error = true; ViewBag.Message = "Error de Permisos"; List <string> backgrounds = Design.getBackgrounds(); return(View("Index", backgrounds)); } } else { //Set error and return to login page ViewBag.Error = true; ViewBag.Message = "Error de Login"; List <string> backgrounds = Design.getBackgrounds(); return(View("Index", backgrounds)); } }
/// <summary> /// newProfile /// </summary> /// <param name="idProfile"></param> /// <param name="idProcess"></param> public ActionResult newProfile(string idProfile = null, string idProcess = null) { bool upd = false; bool updclient = false; String dataPermissions = Session["Permissions"].ToString(); String dataPermissionsClient = Session["PermissionsClient"].ToString(); bool access = false; bool accessClient = false; // access = getpermissions("users", "r"); access = validatepermissions.getpermissions("profiles", "r", dataPermissions); accessClient = validatepermissions.getpermissions("custom_fields", "r", dataPermissionsClient); upd = validatepermissions.getpermissions("profiles", "u", dataPermissions); updclient = validatepermissions.getpermissions("custom_fields", "u", dataPermissionsClient); if (idProfile != null && (upd == false || updclient == false)) { access = false; accessClient = false; } if (access == true && accessClient == true) { CustomFieldsTable cft = new CustomFieldsTable("MovementFields"); String fieldsArray = cft.GetRows(); JArray fields = JsonConvert.DeserializeObject <JArray>(fieldsArray); if (idProfile != null && idProfile != "null" && idProfile != "") { String rowString = _profileTable.GetRow(idProfile); JObject profile = JsonConvert.DeserializeObject <JObject>(rowString); if (profile != null) { String profileJson = JsonConvert.SerializeObject(profile); ViewData["profile"] = new HtmlString(profileJson); } } if (idProcess != null) { String processString = _processesTable.GetRow(idProcess); JObject process = JsonConvert.DeserializeObject <JObject>(processString); if (process != null) { String processJson = JsonConvert.SerializeObject(process); ViewData["process"] = new HtmlString(processJson); } } String rowArray = _profileTable.GetRows(); JArray profiles = JsonConvert.DeserializeObject <JArray>(rowArray); ViewBag.profiles = profiles; return(View(fields)); } else { return(Redirect("~/Home")); } }