Ejemplo n.º 1
0
        private bool UserCanDoByToken(string token, string controllerName, string actionName)
        {
            controllerName = controllerName.ToLower();
            actionName     = actionName.ToLower();


            var action =
                StaticDataHelper.GetCacheDataMenuRole()
                .FirstOrDefault(x => x.Code.ToLower().Equals(actionName) && x.ControllerName.ToLower().Equals(controllerName));

            if (action == null)
            {
                var log = String.Format("UserCanDoByToken(): Token: {0}, controler {1}, action: {2}", token, controllerName, actionName);
                // NLog.LogManager.GetCurrentClassLogger().Debug(log);
                return(true);
            }
            else
            {
                if (string.IsNullOrEmpty(token))
                {
                    return(false);
                }
                var userCheck = StaticDataHelper.GetCacheDataUser().FirstOrDefault(x => x.SessionToken == token);
                //NLog.LogManager.GetCurrentClassLogger().Debug("UserCanDoByToken-userCheck:" + JsonHelper.SerializeObject(userCheck));



                if (userCheck != null)
                {
                    var allowRoles = "," + action.ListRole + ",";
                    //   NLog.LogManager.GetCurrentClassLogger().Debug("UserCanDoByToken-allowRoles" + JsonHelper.SerializeObject(allowRoles));
                    var rs = userCheck.Roles.Any(x => allowRoles.Contains("," + x.Code + ","));
                    return(rs);
                }
            }

            return(false);
        }