protected override bool AuthorizeCore(HttpContextBase httpContext) { var IsAuthorized = base.AuthorizeCore(httpContext); try { if (!IsAuthorized) { return(false); } if (ModuleLevel != null) { var user = Ion_Auth.GetUser(httpContext.User.Identity.Name); var permissions = PermissionModel.GetGroup((int)user.group_id); if (user.groups.name == "admin") { return(true); } if (permissions.ContainsKey(ModuleLevel) == false) { FlashData.SetFlashData("error", "No tienes permiso para ver esta sección."); httpContext.Response.Redirect("/"); return(false); } if (RoleLevel != null && permissions[ModuleLevel].Contains(RoleLevel) == false) { FlashData.SetFlashData("error", "No tienes permiso para realizar esta acción."); httpContext.Response.Redirect("/"); return(false); } } return(true); } catch (Exception ex) { } return(false); }
// // GET: /Admin/ public AdminController(string section = "", string icon = "") { rekursosEntities db = new rekursosEntities(); System.Web.HttpContext HttpContext = System.Web.HttpContext.Current; var type = this.GetType(); ViewBag.Type = type; Dictionary <string, List <Menu> > MenuItems = new Dictionary <string, List <Menu> >(); if (HttpContext.User.Identity.IsAuthenticated) { var User = Ion_Auth.GetUser(HttpContext.User.Identity.Name); ViewBag.UserCurrent = User; Dictionary <string, string[]> ListPermissions = PermissionModel.GetGroup((int)User.group_id); foreach (var module in db.modules.Where(w => w.menu != "0" && w.is_backend == 1).Where(w => w.installed == 1).ToList()) { if (ListPermissions.ContainsKey(module.slug) || User.groups.name == "admin") { if (MenuItems.ContainsKey(module.menu) == false) { MenuItems.Add(module.menu, new List <Menu>()); } MenuItems[module.menu].Add(new Menu { slug = module.slug, name = module.name }); } } } Module ModuleDetails = new Module() { icon = "", description = "", name = "" }; if (section != "") { var module = db.modules.Where(w => w.slug == section).SingleOrDefault(); if (module != null) { //ModuleDetails.ShortCuts = new List<ShortCuts>(); switch (module.slug) { /*case "viaticos": * ModuleDetails.icon = "ion-card"; * break; * case "comisiones": * ModuleDetails.icon = "ion-android-list"; * break; * * case "empleados": * ModuleDetails.icon = "ion-ios-people"; * break; * case "settings": * ModuleDetails.icon = "ion-gear-b"; * break; * case "liquidaciones": * ModuleDetails.icon = "ion-cash"; * break;*/ default: //ModuleDetails.icon = icon; break; } ModuleDetails.name = module.name; ModuleDetails.description = module.description; ///ModuleDetails.ShortCuts.Add(new ShortCuts { Name = "Agregar localidad", Class = "btn btn-success", Uri = "localidades/Create" }); } else { ModuleDetails.icon = "ion-help"; ModuleDetails.name = "NA"; ModuleDetails.description = "Sin descripción del módulo."; } } ViewBag.MenuItems = MenuItems; ViewBag.ModuleDetails = ModuleDetails; }