纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.9 KiB

3 years ago
  1. using NFine.Application.SystemManage;
  2. using NFine.Code;
  3. using System.Text;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. namespace NFine.Web
  7. {
  8. public class HandlerAuthorizeAttribute : ActionFilterAttribute
  9. {
  10. public bool Ignore { get; set; }
  11. public HandlerAuthorizeAttribute(bool ignore = true)
  12. {
  13. Ignore = ignore;
  14. }
  15. public override void OnActionExecuting(ActionExecutingContext filterContext)
  16. {
  17. if (OperatorProvider.Provider.GetCurrent() == null)
  18. {
  19. StringBuilder sbScript = new StringBuilder();
  20. sbScript.Append("<script type='text/javascript'>alert('登录超时,请重新登录!');</script>");
  21. filterContext.Result = new ContentResult() { Content = sbScript.ToString() };
  22. return;
  23. }
  24. if (OperatorProvider.Provider.GetCurrent().IsSystem)
  25. {
  26. return;
  27. }
  28. if (Ignore == false)
  29. {
  30. return;
  31. }
  32. //if (!this.ActionAuthorize(filterContext))
  33. //{
  34. // StringBuilder sbScript = new StringBuilder();
  35. // sbScript.Append("<script type='text/javascript'>alert('很抱歉!您的权限不足,访问被拒绝!');</script>");
  36. // filterContext.Result = new ContentResult() { Content = sbScript.ToString() };
  37. // return;
  38. //}
  39. }
  40. private bool ActionAuthorize(ActionExecutingContext filterContext)
  41. {
  42. var operatorProvider = OperatorProvider.Provider.GetCurrent();
  43. var roleId = operatorProvider.RoleId;
  44. var moduleId = WebHelper.GetCookie("nfine_currentmoduleid");
  45. var action = HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"].ToString();
  46. return new RoleAuthorizeApp().ActionValidate(roleId, moduleId, action);
  47. }
  48. }
  49. }