using NFine.Application.SystemManage;
using NFine.Code;
using System.Text;
using System.Web;
using System.Web.Mvc;
namespace NFine.Web
{
public class HandlerAuthorizeAttribute : ActionFilterAttribute
{
public bool Ignore { get; set; }
public HandlerAuthorizeAttribute(bool ignore = true)
{
Ignore = ignore;
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (OperatorProvider.Provider.GetCurrent() == null)
{
StringBuilder sbScript = new StringBuilder();
sbScript.Append("");
filterContext.Result = new ContentResult() { Content = sbScript.ToString() };
return;
}
if (OperatorProvider.Provider.GetCurrent().IsSystem)
{
return;
}
if (Ignore == false)
{
return;
}
//if (!this.ActionAuthorize(filterContext))
//{
// StringBuilder sbScript = new StringBuilder();
// sbScript.Append("");
// filterContext.Result = new ContentResult() { Content = sbScript.ToString() };
// return;
//}
}
private bool ActionAuthorize(ActionExecutingContext filterContext)
{
var operatorProvider = OperatorProvider.Provider.GetCurrent();
var roleId = operatorProvider.RoleId;
var moduleId = WebHelper.GetCookie("nfine_currentmoduleid");
var action = HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"].ToString();
return new RoleAuthorizeApp().ActionValidate(roleId, moduleId, action);
}
}
}