Example #1
0
        /// <summary>
        /// 检测用户信息
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //检测登陆状态
            var userInfo = Users.GetCurrentLoginUserInfo();

            //log
#pragma warning disable 4014
            AddActionLogAsync(filterContext, userInfo);
#pragma warning restore 4014
            if (userInfo == null)
            {
                Users.LogOut();//无法得到用户信息就登出清空原有cookie再次登陆
                filterContext.Result = AutoResult("登陆失败请重新登陆!", false, Url.Action("index", "login")); return;
            }
            CurrentUserInfo = userInfo;
            //用户角色
            var roleInfo = Roles.GetRoleInfo(CurrentUserInfo.RoleId);
            if (roleInfo == null)
            {
                filterContext.Result = AutoResult("角色不存在!", false);
                return;
            }
            //所有权限
            CurrentUserModuls = roleInfo.IsSuper ? Moduls.GetAllModul() : Moduls.GetIsShowDisplayListByRoleId(CurrentUserInfo.RoleId);
            //装载全局数据
            InitViewData(CurrentUserModuls, CurrentUserInfo);
            //校验权限 排除无需校验权限请求
            if (IsRoleAuthorizeIgnore(filterContext.Controller, filterContext.ActionDescriptor))
            {
                return;
            }
            //超级角色
            if (roleInfo.IsSuper)
            {
                return;
            }
            //开始校验 权限
            if (CurrentUserInfo == null && !roleInfo.IsSuper)
            {
                filterContext.Result = AutoResult("无任何权限!", false);
                return;
            }

            string actionName     = filterContext.RouteData.GetRequiredString("action");
            string controllerName = filterContext.RouteData.GetRequiredString("controller");
            if (
                !CurrentUserModuls.Any(
                    n =>
                    !string.IsNullOrEmpty(n.Controller) &&
                    !string.IsNullOrEmpty(n.Action) &&
                    n.Controller.ToLower() == controllerName.ToLower() &&
                    n.Action.ToLower() == actionName.ToLower()
                    ))
            {
                filterContext.Result = AutoResult("您没有权限!", false);
            }
        }
Example #2
0
        public ActionResult ModulSelect(int?id, int?pid)
        {
            var moduls = Moduls.ModulInfosToTreeVModels(Moduls.GetAllModul(id));

            //选中
            //Moduls.SelectTreeNode(moduls, pid);
            ViewBag.SelectedId = pid;
            return(View(moduls));
        }
Example #3
0
        public ActionResult AllocationModul(int id)
        {
            //查询已有模块 在前端进行默认选中
            int[] mIds = RoleModuls.GetMIds(id);
            ViewBag.SelectedIds = JsonConvert.SerializeObject(mIds.Select(n => "tree_node_" + n).ToList());
            //查询资源树
            var moduls = Moduls.ModulInfosToTreeVModels(Moduls.GetAllModul(id));

            ViewBag.RId = id;
            return(View(moduls));
        }