Esempio n. 1
0
        /// <summary>
        /// 判断用户是否有对应的访问权限
        /// </summary>
        /// <param name="limitId"></param>
        /// <returns></returns>
        public static bool HasPermiss(int limitId)
        {
            var result = false;
            //取缓存的权限
            //var objs = LimitIds;
            var roleBLL = new SysRoleBLL();//测试
            Dictionary <int, int> objs = null;

            if (string.IsNullOrWhiteSpace(CurrentStoreUser.RoleIds))
            {
                objs = roleBLL.GetRoleLimitsByUId(CurrentStoreUser.UID);//测试
            }
            else
            {
                objs = roleBLL.GetRoleLimitsByRoleId(CurrentStoreUser.RoleIds);//门店根据角色
            }
            if (objs == null || objs.Count <= 0)
            {
                //重新初始化当前登录用户权限对象并设置全局缓存
                //SettingLimits(CurrentUser.UID);
                objs = roleBLL.GetRoleLimitsByUId(CurrentStoreUser.UID);
            }
            if (objs != null)
            {
                var curLimits = (Dictionary <int, int>)objs;
                //判断当前用户的权限是否包含数据权限
                if (curLimits.ContainsKey(limitId))
                {
                    result = true;
                    return(result);
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 根据用户UID初始化用户权限对象并设置全局缓存
        /// </summary>
        /// <param name="uid"></param>
        private static void SettingLimits(string uid)
        {
            var ukey = uid + "_" + key_limitId;
            //取权限
            var roleBLL = new SysRoleBLL();
            var objs    = roleBLL.GetRoleLimitsByUId(uid);

            //设置缓存
            var cacheManager = new MemoryCacheManager();

            if (cacheManager.IsSet(ukey))
            {
                cacheManager.Remove(ukey);
            }
            cacheManager.Set(ukey, objs, 1440);
        }