using CRM.Core.BLL.Util; using System; using System.Collections.Generic; using System.Web; using WX.CRM.Common; namespace Core.Web.WebHelper.UserRight { public class UserRightsHelper { public static string[] getUserRights() { string[] userRights = { }; if (HttpContext.Current.Request.IsAuthenticated) { string userId = HttpContext.Current.User.Identity.Name; string cacheKey = "Cache_UserInfo_" + userId; if (CacheHelper.Exists(cacheKey)) { userRights = CacheHelper.Get(cacheKey); } else { LoginHelper login = new LoginHelper(); string[] userrights = login.getRights(Convert.ToInt32(userId)); string userInfoCache = "Cache_UserInfo_" + userId.ToString(); CacheHelper.Set(cacheKey, userrights); userRights = userrights; // FormsAuthentication.SignOut(); } } return userRights ?? new string[] { "-1" }; } public static bool hasRight(string code) { var right = getUserRights(); foreach (var item in right) { if (item.StartsWith(code+"|")) { return true; } } return false; } public static decimal[] InnerGroup(int[] roleId, decimal[] groupId) { decimal[] groups = { 0 }; string roleCodes = new CACHE_BL().Get_RoleCodes(roleId); if (roleCodes.IndexOf("[GLY]") > -1 || roleCodes.IndexOf("[ZJ]") > -1 || roleCodes.IndexOf("ZJZL") > -1 || roleCodes.IndexOf("[BMZG]") > -1) { groups = null; } else { if (groupId != null) { groups = groupId; } } return groups; } public static string[] getUserRightsCodes() { string[] st = getUserRights(); List wocha = new List(); foreach (var item in st) { wocha.Add(item.Split('|')[0]); } return wocha.ToArray(); } public static int getRightButtonId(string rightcode) { string[] rightcodes = UserRightsHelper.getUserRights(); int butonid = 0; foreach (string code in rightcodes) { if (code.IndexOf(string.Format("{0}|", rightcode)) > -1) { string[] codeAndBtnId = code.Split('|'); butonid = Convert.ToInt32(codeAndBtnId[1]); break; } } return butonid; } public static string GetUserButtonSite(string rightcode, int buttonid) { var site = ""; if (HttpContext.Current.Request.IsAuthenticated) { string userId = HttpContext.Current.User.Identity.Name; string cacheKey = $"Cache_UserInfo_{userId}_{rightcode}_{buttonid}"; if (CacheHelper.Exists(cacheKey)) { site = CacheHelper.Get(cacheKey); } else { LoginHelper login = new LoginHelper(); site = login.GetUserButtonSite(rightcode, buttonid); CacheHelper.Set(cacheKey, site); // FormsAuthentication.SignOut(); } } return site; } } }