Exemple #1
0
        public virtual bool Authorize(Site site, string userName, Kooboo.CMS.Account.Models.Permission permission)
        {
            string contextKey = "Permission:" + permission.ToString();
            var    allow      = CallContext.Current.GetObject <bool?>(contextKey);

            if (!allow.HasValue)
            {
                allow = false;

                if (IsAdministrator(userName))
                {
                    allow = true;
                }
                else if (site != null)
                {
                    var siteUser = this.Get(site, userName);

                    if (siteUser != null && siteUser.Roles != null)
                    {
                        allow = siteUser.Roles.Select(it => Kooboo.CMS.Account.Services.ServiceFactory.RoleManager.Get(it))
                                .Any(it => it != null && it.HasPermission(permission));
                    }
                }

                CallContext.Current.RegisterObject(contextKey, allow);
            }
            return(allow.Value);
        }
Exemple #2
0
        public virtual bool Authorize(Site site, string userName, Kooboo.CMS.Account.Models.Permission permission)
        {
            string contextKey = "Permission:" + permission.ToString();
            var    allow      = CallContext.Current.GetObject <bool?>(contextKey);

            if (!allow.HasValue)
            {
                allow = false;

                if (IsAdministrator(userName))
                {
                    allow = true;
                }
                else
                {
                    var roles = GetRoles(site, userName);
                    allow = roles.Any(it => it.HasPermission(permission));
                }
                CallContext.Current.RegisterObject(contextKey, allow);
            }
            return(allow.Value);
        }