添加项目文件。

This commit is contained in:
dell
2023-03-03 16:07:50 +08:00
parent 2c462551b6
commit 011039960e
585 changed files with 362460 additions and 0 deletions

View File

@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace HT.Cloud.Code
{
/// <summary>
/// 管理员特性MVC使用
/// </summary>
public class HandlerAdminAttribute : ActionFilterAttribute
{
private readonly bool _isSuper;
public HandlerAdminAttribute(bool isSuper = true)
{
_isSuper = isSuper;
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (OperatorProvider.Provider.GetCurrent() != null && _isSuper == true ? OperatorProvider.Provider.GetCurrent().IsSuperAdmin : OperatorProvider.Provider.GetCurrent().IsAdmin)
{
return;
}
else
{
//filterContext.HttpContext.Response.WriteAsync("<script>top.location.href ='" + filterContext.HttpContext.Request.PathBase + "/Home/Error?msg=403" + "';if(document.all) window.event.returnValue = false;</script>");
filterContext.Result = new RedirectResult(filterContext.HttpContext.Request.PathBase + "/Home/Error?msg=403");
return;
}
}
}
}

View File

@ -0,0 +1,34 @@
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ActionConstraints;
using Microsoft.AspNetCore.Routing;
using System;
namespace HT.Cloud.Code
{
/// <summary>
/// ajax验证
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class HandlerAjaxOnlyAttribute : ActionMethodSelectorAttribute
{
public bool Ignore { get; set; }
public HandlerAjaxOnlyAttribute(bool ignore = false)
{
Ignore = ignore;
}
public override bool IsValidForRequest(RouteContext routeContext, ActionDescriptor action)
{
if (Ignore)
return true;
bool result = false;
var xreq = routeContext.HttpContext.Request.Headers.ContainsKey("x-requested-with");
if (xreq)
{
result = routeContext.HttpContext.Request.Headers.ContainsKey("x-requested-with");
}
return result;
}
}
}

View File

@ -0,0 +1,56 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace HT.Cloud.Code
{
/// <summary>
/// 防重复锁MVC使用
/// </summary>
public class HandlerLockAttribute : ActionFilterAttribute
{
public HandlerLockAttribute()
{
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (OperatorProvider.Provider.GetCurrent() == null)
{
WebHelper.WriteCookie("WaterCloud_login_error", "overdue");
//filterContext.HttpContext.Response.WriteAsync("<script>top.location.href ='" + filterContext.HttpContext.Request.PathBase + "/Home/Error?msg=408" + "';if(document.all) window.event.returnValue = false;</script>");
OperatorProvider.Provider.EmptyCurrent("pc_").GetAwaiter().GetResult();
filterContext.Result = new RedirectResult(filterContext.HttpContext.Request.PathBase + "/Home/Error?msg=408");
return;
}
else
{
string token = filterContext.HttpContext.Request.Cookies["pc_" + GlobalContext.SystemConfig.TokenName];
string cacheToken = CacheHelper.GetAsync<string>("pc_" + GlobalContext.SystemConfig.TokenName + "_" + OperatorProvider.Provider.GetCurrent().UserId + "_" + OperatorProvider.Provider.GetCurrent().LoginTime).GetAwaiter().GetResult();
if (string.IsNullOrWhiteSpace(token))
{
filterContext.Result = new JsonResult(new AlwaysResult { state = ResultType.error.ToString(), message = "token不能空" });
return;
}
if (string.IsNullOrWhiteSpace(cacheToken))
{
filterContext.Result = new JsonResult(new AlwaysResult { state = ResultType.error.ToString(), message = "token不能空" });
return;
}
if (token != cacheToken)
{
filterContext.Result = new JsonResult(new AlwaysResult { state = ResultType.error.ToString(), message = "请求异常" });
return;
}
//固定加锁5秒
bool result = CacheHelper.SetNx(token, token, 5);
if (!result)
{
filterContext.Result = new JsonResult(new AlwaysResult { state = ResultType.error.ToString(), message = "请求太频繁,请稍后" });
return;
}
}
//随机值
base.OnActionExecuting(filterContext);
}
}
}

View File

@ -0,0 +1,52 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System.Diagnostics;
using System.Threading.Tasks;
namespace HT.Cloud.Code
{
/// <summary>
/// 防重复提交,api使用
/// </summary>
public class LockAttribute : ActionFilterAttribute
{
/// <summary>
/// 拦截
/// </summary>
/// <param name="context"></param>
/// <param name="next"></param>
/// <returns></returns>
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
Stopwatch sw = new Stopwatch();
sw.Start();
if (GlobalContext.SystemConfig.Debug == false)
{
if (OperatorProvider.Provider.GetCurrent() == null)
{
context.Result = new JsonResult(new AlwaysResult { state = ResultType.error.ToString(), message = "抱歉,没有操作权限" });
return;
}
else
{
string token = context.HttpContext.Request.Headers[GlobalContext.SystemConfig.TokenName].ParseToString();
if (string.IsNullOrWhiteSpace(token))
{
context.Result = new JsonResult(new AlwaysResult { state = ResultType.error.ToString(), message = "token不能空" });
return;
}
//固定加锁5秒
bool result = CacheHelper.SetNx(token, token, 5);
if (!result)
{
context.Result = new JsonResult(new AlwaysResult { state = ResultType.error.ToString(), message = "请求太频繁,请稍后" });
return;
}
}
}
await next();
sw.Stop();
}
}
}

View File

@ -0,0 +1,23 @@
using System;
namespace HT.Cloud.Code
{
[AttributeUsage(AttributeTargets.Class, Inherited = true)]
public class ServiceDescriptionAttribute : Attribute
{
public string ClassDescription
{
get;
set;
}
private ServiceDescriptionAttribute()
{
}
public ServiceDescriptionAttribute(string classDescription)
{
ClassDescription = classDescription;
}
}
}