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.

50 lines
2.1 KiB

2 weeks 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().UserCode == null)
  18. {
  19. StringBuilder sbScript = new StringBuilder();
  20. //sbScript.Append("<script type='text/javascript'>alert('登录超时,请重新登录!');</script>");
  21. sbScript.Append("<script>top.location.href = '/Login/Index';</script>;<script type='text/javascript'>alert('系统超时,请重新登录!')</script> ");
  22. filterContext.Result = new ContentResult() { Content = sbScript.ToString() };
  23. return;
  24. }
  25. if (OperatorProvider.Provider.GetCurrent().IsSystem)
  26. {
  27. return;
  28. }
  29. if (Ignore == false)
  30. {
  31. return;
  32. }
  33. //if (!this.ActionAuthorize(filterContext))
  34. //{
  35. // StringBuilder sbScript = new StringBuilder();
  36. // sbScript.Append("<script type='text/javascript'>alert('很抱歉!您的权限不足,访问被拒绝!');</script>");
  37. // filterContext.Result = new ContentResult() { Content = sbScript.ToString() };
  38. // return;
  39. //}
  40. }
  41. private bool ActionAuthorize(ActionExecutingContext filterContext)
  42. {
  43. var operatorProvider = OperatorProvider.Provider.GetCurrent();
  44. var roleId = operatorProvider.RoleId;
  45. var moduleId = WebHelper.GetCookie("nfine_currentmoduleid");
  46. var action = HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"].ToString();
  47. return new RoleAuthorizeApp().ActionValidate(roleId, moduleId, action);
  48. }
  49. }
  50. }