Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
gameking0124 committed Jul 8, 2017
0 parents commit 43092eb
Show file tree
Hide file tree
Showing 2,217 changed files with 667,447 additions and 0 deletions.
28 changes: 28 additions & 0 deletions FoxOne.Business/AjaxResultModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FoxOne.Business
{
public class AjaxResultModel
{
public object Data { get; set; }

public bool Result { get; set; }

public string ErrorMessage { get; set; }

public bool NoAuthority { get; set; }

public bool LoginTimeOut { get; set; }

public AjaxResultModel()
{
this.Result = true;
this.ErrorMessage = string.Empty;
this.NoAuthority = false;
this.LoginTimeOut = false;
}
}
}
79 changes: 79 additions & 0 deletions FoxOne.Business/Attribute/CustomAuthorizeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using FoxOne.Business.Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using FoxOne.Core;
namespace FoxOne.Business
{
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
if (filterContext.HttpContext.Request.IsAjaxRequest())
{

var result = new AjaxResultModel()
{
LoginTimeOut = true,
ErrorMessage = "登录超时"
};
if (filterContext.HttpContext.Response.StatusCode == 403)
{
filterContext.HttpContext.Response.StatusCode = 200;
result.NoAuthority = true;
result.ErrorMessage = "您没有访问资源[" + filterContext.RouteData.Values["controller"].ToString() + "/" + filterContext.RouteData.Values["action"].ToString() + "]的权限";
}
filterContext.Result = new JsonResult()
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = result
};
}
else
{
base.HandleUnauthorizedRequest(filterContext);
}
}

protected override bool AuthorizeCore(HttpContextBase httpContext)
{
var returnValue = httpContext.User.Identity.IsAuthenticated;
if (returnValue)
{
var request = httpContext.Request;
if (!Sec.Provider.HasPermissionOfUrl(request.Path, request.Url.Query))
{
httpContext.Response.StatusCode = 403;
if (httpContext.Request.IsAjaxRequest())
{
returnValue = false;
}
else
{
string redirect = "~/Home/Error/您没有访问该页面的权限";
httpContext.Response.Redirect(redirect);
httpContext.Response.End();
}
}
}
return returnValue;
}

public override void OnAuthorization(AuthorizationContext filterContext)
{
var attr = filterContext.ActionDescriptor.GetCustomAttributes(typeof(CustomUnAuthorizeAttribute), true);
if (attr.IsNullOrEmpty())
{
base.OnAuthorization(filterContext);
}
}
}

public class CustomUnAuthorizeAttribute : Attribute
{

}
}
59 changes: 59 additions & 0 deletions FoxOne.Business/Attribute/CustomHandleErrorAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using FoxOne.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace FoxOne.Business
{
public class CustomHandleErrorAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
Logger.Error(filterContext.Exception.Message, filterContext.Exception);
if (!(filterContext.Exception is FoxOneException))
{
//预料之外的异常,记录日志

}
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
filterContext.ExceptionHandled = true;
filterContext.HttpContext.Response.Clear();
JsonResult json = new JsonResult();
AjaxResultModel result = new AjaxResultModel()
{
Result = false,
//ErrorMessage = "出错的地址是:" + filterContext.RouteData.Values["controller"].ToString() + "/" + filterContext.RouteData.Values["action"].ToString() + "\n异常信息为:" + filterContext.Exception.Message
ErrorMessage = filterContext.Exception.Message
};
json.Data = result;
json.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
filterContext.Result = json;
}
else
{
filterContext.ExceptionHandled = true;
filterContext.HttpContext.Response.Clear();
string message = string.Empty;
if (filterContext.Exception is PageNotFoundException)
{
filterContext.HttpContext.Response.StatusCode = 404;
message = "页面不存在";
}
else if (filterContext.Exception is UnAuthorizedException)
{
filterContext.HttpContext.Response.StatusCode = 403;
message = "您没有访问该页面的权限";
}
else
{
filterContext.HttpContext.Response.StatusCode = 500;
message = filterContext.Exception.Message;
}
filterContext.Result = new RedirectResult("/Home/Error/" + message);
}
}
}
}
61 changes: 61 additions & 0 deletions FoxOne.Business/Attribute/DataSourceAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FoxOne.Business
{
public abstract class DataSourceAttribute : Attribute
{
public abstract IControl GetDataSource();
}

public class EnumDataSourceAttribute : DataSourceAttribute
{
private Type EnumType { get; set; }
public EnumDataSourceAttribute(Type type)
{
if (!type.IsEnum)
{
throw new ArgumentOutOfRangeException("type");
}
EnumType = type;
}

public override IControl GetDataSource()
{
var result = new EnumDataSource();
result.EnumType = EnumType;
result.EnumValueType = EnumValueType.Code;
return result;
}
}

public class FunctionDataSourceAttribute : DataSourceAttribute
{
private Type Type { get; set; }

public FunctionDataSourceAttribute(Type type)
{
Type = type;
}
public override IControl GetDataSource()
{
return Activator.CreateInstance(Type) as IControl;
}
}

public class TypeDataSourceAttribute : DataSourceAttribute
{
private Type Type { get; set; }

public TypeDataSourceAttribute(Type type)
{
Type = type;
}
public override IControl GetDataSource()
{
return new TypeDataSource() { BaseType = Type } as IKeyValueDataSource;
}
}
}
24 changes: 24 additions & 0 deletions FoxOne.Business/Attribute/FormFieldAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FoxOne.Business
{
[AttributeUsage(AttributeTargets.Property,Inherited=true)]
public class FormFieldAttribute : Attribute
{
public FormFieldAttribute()
{
ControlType = ControlType.None;
Editable = true;
}
public string FormDisplayName { get; set; }

public ControlType ControlType { get; set; }

public bool Editable { get; set; }

public object DefaultValue { get; set; }
}
}
12 changes: 12 additions & 0 deletions FoxOne.Business/Attribute/HtmlEncodeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FoxOne.Business
{
public class HtmlEncodeAttribute:Attribute
{

}
}
11 changes: 11 additions & 0 deletions FoxOne.Business/Attribute/ParentFieldAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FoxOne.Business
{
public class ParentFieldAttribute:Attribute
{
}
}
17 changes: 17 additions & 0 deletions FoxOne.Business/Attribute/ScriptNameAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FoxOne.Business
{
public class ScriptNameAttribute:Attribute
{
public string Name { get; set; }

public ScriptNameAttribute(string name)
{
Name = name;
}
}
}
34 changes: 34 additions & 0 deletions FoxOne.Business/Attribute/TableFieldAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FoxOne.Business
{
public class TableFieldAttribute:Attribute
{
public TableFieldAttribute()
{
IsShow = true;
}
public int ShowLength { get; set; }

public string ColumnWidth { get; set; }

public string DefaultValue { get; set; }

public CellTextAlign TextAlign { get; set; }

public string DataFormatString { get; set; }

public string DataFormatFields { get; set; }

public string ReferenceField { get; set; }

public bool Sortable { get; set; }

public bool IsShow { get; set; }

public bool HtmlEncode { get; set; }
}
}
11 changes: 11 additions & 0 deletions FoxOne.Business/Attribute/TitleFieldAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FoxOne.Business
{
public class TitleFieldAttribute:Attribute
{
}
}
18 changes: 18 additions & 0 deletions FoxOne.Business/Attribute/ValidatorAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FoxOne.Business
{
public class ValidatorAttribute:Attribute
{
public string ValidateString { get; set; }

public ValidatorAttribute(string validateString)
{
ValidateString = validateString;
}

}
}
Loading

0 comments on commit 43092eb

Please sign in to comment.