Ejemplo n.º 1
0
 public static bool CanUnban(Authentication authentication, IUserDescriptor descriptor)
 {
     if (authentication.ID == descriptor.UserInfo.ID)
     {
         return(false);
     }
     if (authentication.Authority != Authority.Admin)
     {
         return(false);
     }
     return(UserDescriptorUtility.IsBanned(authentication, descriptor) == true);
 }
Ejemplo n.º 2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (Authenticator.Current == null)
            {
                return(value);
            }

            if (parameter == null)
            {
                parameter = this.PropertyName;
            }

            if (value != null && parameter is string propertyName)
            {
                if (value is IUserDescriptor descriptor)
                {
                    if (propertyName == IsOnline)
                    {
                        return(UserDescriptorUtility.IsOnline(Authenticator.Current, descriptor));
                    }
                    else if (propertyName == IsBanned)
                    {
                        return(UserDescriptorUtility.IsBanned(Authenticator.Current, descriptor));
                    }
                    else if (propertyName == IsAdmin)
                    {
                        return(UserDescriptorUtility.IsAdmin(Authenticator.Current, descriptor));
                    }
                    else if (propertyName == IsMember)
                    {
                        return(UserDescriptorUtility.IsMember(Authenticator.Current, descriptor));
                    }
                    else if (propertyName == IsGuest)
                    {
                        return(UserDescriptorUtility.IsGuest(Authenticator.Current, descriptor));
                    }
                }
                else
                {
                    var prop = value.GetType().GetProperty(propertyName);
                    if (prop != null)
                    {
                        return(prop.GetValue(value));
                    }
                }
            }
            return(value);
        }