37 lines
914 B
C#
37 lines
914 B
C#
namespace YLErp.Web
|
|
{
|
|
[AttributeUsage(AttributeTargets.Method)]
|
|
public class MyAuthorizeAttribute : Attribute
|
|
{
|
|
readonly string[] _rightNames;
|
|
|
|
protected MyAuthorizeAttribute()
|
|
{
|
|
|
|
}
|
|
|
|
public MyAuthorizeAttribute(string rightNames)
|
|
{
|
|
_rightNames = rightNames.Split(',').Where(n => !string.IsNullOrWhiteSpace(n)).Select(n => n.Trim()).ToArray();
|
|
}
|
|
|
|
public virtual bool HasRight(UserInfo userInfo)
|
|
{
|
|
return userInfo != null && _rightNames.Any(r => userInfo.HasRight(r));
|
|
}
|
|
}
|
|
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
|
|
public class MyAuthorizeIgnoreAttribute : MyAuthorizeAttribute
|
|
{
|
|
public MyAuthorizeIgnoreAttribute()
|
|
{
|
|
|
|
}
|
|
|
|
public override bool HasRight(UserInfo userInfo)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
} |