using System; using System.Collections.Generic; using System.Linq; using System.Web; using WcfServiceAuthentication; namespace DeiNiu.wms.Logical { public class ConstAuthourity { public static Dictionary userKeyPares = new Dictionary(); public static Dictionary> userSpecialAuths = new Dictionary>() ; public static List getAuthorities(int userId) { int randomCode = 0; if(AuthenticationInspector.tmpCodes.ContainsKey(userId)) { randomCode = AuthenticationInspector.tmpCodes[userId]; if (randomCode == 0) { return new List(); } } foreach (int key in userKeyPares.Keys) { if(userKeyPares[key] == randomCode) { userKeyPares[key] = getRandom(); return userSpecialAuths[key]; } } return new List(); } public static void setSpecialAuths(int userId, List specialAuths) { userKeyPares[userId] = getRandom(); userSpecialAuths[userId] = specialAuths; } private static int getRandom() { return new Random().Next(1000, 9000); } public static bool havePermission(int userId,string permission) { return userSpecialAuths.ContainsKey(userId) && userSpecialAuths[userId].Contains(permission) ||getAuthorities(userId).Contains(permission); } } }