Esempio n. 1
0
        static AdminPermission()
        {
            AdminPermission.ActionPermissions = AdminPermission.GetAllActionByAssembly();
            AdminPermission.privileges        = new Dictionary <AdminPrivilege, IEnumerable <ActionPermission> >();
            IEnumerable <List <ActionItem> > privilege =
                from a in PrivilegeHelper.GetPrivileges <AdminPrivilege>().Privilege
                select a.Items;

            foreach (List <ActionItem> actionItems in privilege)
            {
                foreach (ActionItem actionItem in actionItems)
                {
                    List <ActionPermission> actionPermissions = new List <ActionPermission>();
                    foreach (Controllers controller in actionItem.Controllers)
                    {
                        foreach (string actionName in controller.ActionNames)
                        {
                            actionPermissions.AddRange(AdminPermission.GetActionByControllerName(controller.ControllerName, actionName));
                        }
                    }
                    AdminPermission.privileges.Add((AdminPrivilege)actionItem.PrivilegeId, actionPermissions);
                }
            }
        }
Esempio n. 2
0
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            //TODO:DZY[150731] 与父级方法冲突,改为数据直接补充
            InitVisitorTerminal();

            var t = ConfigurationManager.AppSettings["IsInstalled"];

            if (!(null == t || bool.Parse(t)))
            {
                return;
            }
            //不能应用在子方法上
            if (filterContext.IsChildAction)
            {
                return;
            }
            if (CurrentManager == null)
            {
                if (Core.Helper.WebHelper.IsAjax())
                {
                    Result result = new Result();
                    result.msg           = "登录超时,请重新登录!";
                    result.success       = false;
                    filterContext.Result = Json(result);
                    return;
                }
                else
                {
                    var result = RedirectToAction("", "Login", new { area = "admin" });
                    filterContext.Result = result;
                    return;
                    //跳转到登录页
                }
            }
            object[] actionFilter = filterContext.ActionDescriptor.GetCustomAttributes(typeof(UnAuthorize), false);
            if (actionFilter.Length == 1)
            {
                return;
            }
            var controllerName = filterContext.RouteData.Values["controller"].ToString().ToLower();
            var actionName     = filterContext.RouteData.Values["action"].ToString().ToLower();

            if (CurrentManager.AdminPrivileges == null || CurrentManager.AdminPrivileges.Count == 0 || !AdminPermission.CheckPermissions(CurrentManager.AdminPrivileges, controllerName, actionName))
            {
                if (Core.Helper.WebHelper.IsAjax())
                {
                    Result result = new Result();
                    result.msg           = "你没有访问的权限!";
                    result.success       = false;
                    filterContext.Result = Json(result);
                    return;
                }
                else
                {
                    //跳转到错误页
                    var result = new ViewResult()
                    {
                        ViewName = "NoAccess"
                    };
                    result.TempData.Add("Message", "你没有权限访问此页面");
                    result.TempData.Add("Title", "你没有权限访问此页面!");
                    filterContext.Result = result;
                    return;
                }
            }
        }
Esempio n. 3
0
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.InitVisitorTerminal();
            string item = ConfigurationManager.AppSettings["IsInstalled"];

            if (item != null && !bool.Parse(item))
            {
                return;
            }
            if (filterContext.IsChildAction)
            {
                return;
            }
            if (CurrentManager == null)
            {
                if (!WebHelper.IsAjax())
                {
                    RedirectToRouteResult action = base.RedirectToAction("", "Login", new { area = "admin" });
                    filterContext.Result = action;
                    return;
                }
                BaseController.Result result = new BaseController.Result()
                {
                    msg     = "登录超时,请重新登录!",
                    success = false
                };
                filterContext.Result = base.Json(result);
                return;
            }
            if (filterContext.ActionDescriptor.GetCustomAttributes(typeof(UnAuthorize), false).Length == 1)
            {
                return;
            }
            string lower = filterContext.RouteData.Values["controller"].ToString().ToLower();
            string str   = filterContext.RouteData.Values["action"].ToString().ToLower();

            if (CurrentManager.AdminPrivileges == null || CurrentManager.AdminPrivileges.Count == 0 || !AdminPermission.CheckPermissions(CurrentManager.AdminPrivileges, lower, str))
            {
                if (WebHelper.IsAjax())
                {
                    BaseController.Result result1 = new BaseController.Result()
                    {
                        msg     = "你没有访问的权限!",
                        success = false
                    };
                    filterContext.Result = base.Json(result1);
                    return;
                }
                ViewResult viewResult = new ViewResult()
                {
                    ViewName = "NoAccess"
                };
                viewResult.TempData.Add("Message", "你没有权限访问此页面");
                viewResult.TempData.Add("Title", "你没有权限访问此页面!");
                filterContext.Result = viewResult;
            }
        }