PermissionAttribute.cs 972 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // <author></author>
  2. // <date></date>
  3. // <description></description>
  4. using ERP.Framework.Constants;
  5. using ERP.Framework.Security;
  6. using Microsoft.AspNetCore.Mvc.Filters;
  7. namespace ERP.Framework.Attribute
  8. {
  9. /// <summary>
  10. /// 接口权限特性
  11. /// </summary>
  12. [AttributeUsage(AttributeTargets.Method)]
  13. public class PermissionAttribute : ActionFilterAttribute
  14. {
  15. internal string Code { get; set; }
  16. public PermissionAttribute(string code)
  17. {
  18. Code = code;
  19. }
  20. public override void OnActionExecuted(ActionExecutedContext context)
  21. {
  22. var loginUser = LoginHelper.GetLoginUser();
  23. if (loginUser.Permission.Contains(FrameworkConstant.ADMIN_PERMISSION))
  24. {
  25. return;
  26. }
  27. if (!loginUser.Permission.Contains(this.Code))
  28. {
  29. //throw new Exception(AuthI18N.NoPermission);
  30. }
  31. }
  32. }
  33. }