Пример #1
0
        public bool ValiddatePermission(string token, string controller, string action, string filePath)
        {
            bool bResult = false;

            List <perm> perm = null;

            perm = (List <perm>)HttpContext.Current.Session[filePath];
            if (perm == null)
            {
                SysUserBLL userBLL = new SysUserBLL();
                {
                    var userName = LoginUserManage.DecryptToken(token.Trim());
                    perm = userBLL.GetPermission(userName, controller); //获取当前用户的权限列表
                    HttpContext.Current.Session[filePath] = perm;       //获取的劝降放入会话由Controller调用
                }
            }
            //查询当前Action 是否有操作权限,大于0表示有,否则没有
            int count = perm.Where(a => a.KeyCode.ToLower() == action.ToLower()).Count();

            if (count > 0)
            {
                bResult = true;
            }
            else
            {
                bResult = false;
                LoginUserManage.RedirectUrlFor401();
            }


            return(bResult);
        }
Пример #2
0
        public bool ValidDataPermission(AccountModel account, string controller, string action, string filePath)
        {
            //throw new NotImplementedException();
            bool   bResult    = false;
            string actionName = string.IsNullOrEmpty(ActionName) ? action : ActionName;

            if (account != null)
            {
                List <permModel> perm = null;
                //测试当前controller是否已赋权限值,如果没有从
                //如果存在区域,Seesion保存(区域+控制器)
                if (!string.IsNullOrEmpty(Area))
                {
                    controller = Area + "/" + controller;
                }

                perm = (List <permModel>)HttpContext.Current.Session[filePath];
                if (perm == null)
                {
                    using (SysUserBLL userBLL = new SysUserBLL()
                    {
                        sysRightRepository = new SysRightRepository()
                    })
                    {
                        perm = userBLL.GetPermission(account.Id, controller); //获取当前用户的权限列表
                        HttpContext.Current.Session[filePath] = perm;         //获取的权限放入会话由Controller调用
                    }
                }
                //当用户访问index时,只要权限>0就可以访问
                if (actionName.ToLower() == "index")
                {
                    if (perm.Count > 0)
                    {
                        return(true);
                    }
                }
                //查询当前Action 是否有操作权限,大于0表示有,否则没有
                int count = perm.Where(a => a.KeyCode.ToLower() == actionName.ToLower()).Count();
                if (count > 0)
                {
                    bResult = true;
                }
                else
                {
                    bResult = false;
                    HttpContext.Current.Response.Write("你没有操作权限,请联系管理员!");
                }
            }
            return(bResult);
        }
Пример #3
0
        public bool ValiddatePermission(AccountModel account, string controller, string action, string filePath)
        {
            bool   bResult    = false;
            string actionName = string.IsNullOrEmpty(ActionName) ? action : ActionName;

            if (account != null)
            {
                List <permModel> perm = null;
                //测试当前controller是否已赋权限值,如果没有从
                //如果存在区域,Seesion保存(区域+控制器)
                if (!string.IsNullOrEmpty(Area))
                {
                    controller = Area + "/" + controller;
                }
                perm = (List <permModel>)HttpContext.Current.Session[filePath];
                if (perm == null)
                {
                    SysUserBLL userBLL = new SysUserBLL()
                    {
                        m_Rep       = new SysUserRepository(new DBContainer()),
                        sysRightRep = new SysRightRepository(new DBContainer())
                    };
                    {
                        perm = userBLL.GetPermission(account.Id, controller); //获取当前用户的权限列表
                        HttpContext.Current.Session[filePath] = perm;         //获取的权限放入会话由Controller调用
                    }
                }
                //用户即使没有某功能的操作权限也可以访问该功能的index界面,只是该界面的perm受限于上诉session的perm
                if (actionName.ToLower() == "index")
                {
                    // if (perm.Count >= 0)
                    // {
                    return(true);
                    //  }
                }
                //查询当前Action 是否有操作权限,大于0表示有,否则没有
                int count = perm.Where(a => a.KeyCode.ToLower().Trim() == actionName.ToLower().Trim()).Count();
                //if (count > 0)
                //{
                //    bResult = true;
                //}
                //else
                //{
                //    bResult = false;
                //    LoginUserManage.RedirectUrl();
                //}
            }
            return(true);
        }
Пример #4
0
        public bool ValiddatePermission(Account account, string controller, string action, string filePath)
        {
            #region 权限分配到Action单位时使用
            bool   bResult    = false;
            string actionName = string.IsNullOrEmpty(ActionName) ? action : ActionName;
            if (account != null)
            {
                List <perm> perm = null;
                //测试当前controller是否已赋权限值,如果没有从
                //如果存在区域,Seesion保存(区域+控制器)
                if (!string.IsNullOrEmpty(Area))
                {
                    controller = Area + "/" + controller;
                }
                perm = (List <perm>)HttpContext.Current.Session[filePath];
                if (perm == null || perm.Count == 0)
                {
                    SysUserBLL userBLL = new SysUserBLL();
                    {
                        perm = userBLL.GetPermission(account.Id, (controller).ToLower()); //获取当前用户的权限列表
                        HttpContext.Current.Session[filePath] = perm;                     //获取的劝降放入会话由Controller调用
                    }
                }
                //当用户访问index时,只要权限>0就可以访问
                if (actionName.ToLower() == "index")
                {
                    if (perm.Count > 0)
                    {
                        return(true);
                    }
                }
                //查询当前Action 是否有操作权限,大于0表示有,否则没有
                int count = perm.Where(a => a.KeyCode == actionName).Count();
                if (count > 0 || account.Id == "1")
                {
                    bResult = true;
                }
                else
                {
                    bResult = false;
                    LoginUserManage.RedirectUrl();
                }
            }
            return(bResult);

            #endregion
        }
        public bool ValiddatePermission(AccountModel account, string controller, string action, string filePath)
        {
            bool   bResult    = false;
            string actionName = string.IsNullOrEmpty(ActionName) ? action : ActionName;

            if (account != null)
            {
                List <permModel> perm = null;

                if (!string.IsNullOrEmpty(Area))
                {
                    controller = Area + "/" + controller;
                }
                perm = (List <permModel>)HttpContext.Current.Session[filePath];
                if (perm == null)
                {
                    IBLL.ISysUserBLL userBLL = new SysUserBLL();
                    {
                        perm = userBLL.GetPermission(account.Id, controller);
                        HttpContext.Current.Session[filePath] = perm;
                    }
                }

                if (actionName.ToLower() == "index")
                {
                    if (perm.Count > 0)
                    {
                        return(true);
                    }
                }

                int count = perm.Where(a => a.KeyCode.ToLower() == actionName.ToLower()).Count();
                if (count > 0)
                {
                    bResult = true;
                }
                else
                {
                    bResult = false;
                    HttpContext.Current.Response.Write("你没有操作权限,请联系管理员!");
                }
            }
            return(bResult);
        }