update:操作日志特性
This commit is contained in:
18
Api/Ewide.Core/Attributes/OpAttribute.cs
Normal file
18
Api/Ewide.Core/Attributes/OpAttribute.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Attributes
|
||||
{
|
||||
public class OpAttribute : Attribute
|
||||
{
|
||||
private readonly LogOpType logOpType;
|
||||
public OpAttribute(LogOpType logOpType)
|
||||
{
|
||||
this.logOpType = logOpType;
|
||||
}
|
||||
public int OpType { get => (int)logOpType; }
|
||||
}
|
||||
}
|
||||
@@ -2784,6 +2784,13 @@
|
||||
请求日志拦截
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Ewide.Core.RequestActionFilter.InferOpType(Microsoft.AspNetCore.Http.HttpRequest)">
|
||||
<summary>
|
||||
使用路由推断
|
||||
</summary>
|
||||
<param name="request"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Ewide.Core.UserManager">
|
||||
<summary>
|
||||
用户管理
|
||||
|
||||
@@ -10,6 +10,9 @@ using System.Threading.Tasks;
|
||||
using UAParser;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Reflection;
|
||||
using Ewide.Core.Attributes;
|
||||
using System.Linq;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
@@ -36,6 +39,11 @@ namespace Ewide.Core
|
||||
var actionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
|
||||
var descAtt = Attribute.GetCustomAttribute(actionDescriptor.MethodInfo, typeof(DescriptionAttribute)) as DescriptionAttribute;
|
||||
|
||||
//获取操作类型
|
||||
var method = actionDescriptor.MethodInfo;
|
||||
var opAttr = method.GetCustomAttribute<OpAttribute>();
|
||||
var opType = opAttr?.OpType ?? InferOpType(httpRequest);
|
||||
|
||||
var message = "请求成功";
|
||||
if (isRequestSucceed)
|
||||
{
|
||||
@@ -56,7 +64,7 @@ namespace Ewide.Core
|
||||
var sysOpLog = new SysLogOp
|
||||
{
|
||||
Name = descAtt != null ? descAtt.Description : actionDescriptor.ActionName,
|
||||
OpType = 1,
|
||||
OpType = opType,
|
||||
Success = isRequestSucceed,
|
||||
Message = message,
|
||||
Ip = httpContext.GetRemoteIpAddressToIPv4(),
|
||||
@@ -75,5 +83,28 @@ namespace Ewide.Core
|
||||
};
|
||||
await sysOpLog.InsertNowAsync();
|
||||
}
|
||||
/// <summary>
|
||||
/// 使用路由推断
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
int InferOpType(HttpRequest request)
|
||||
{
|
||||
var lastRoute = request.Path.Value.Split("/").Last();
|
||||
var opNames = Enum.GetNames(typeof(LogOpType));
|
||||
foreach (var op in opNames)
|
||||
{
|
||||
if (lastRoute.Contains(op, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return (int)Enum.Parse(typeof(LogOpType), op);
|
||||
}
|
||||
}
|
||||
if (lastRoute.Contains("page", StringComparison.OrdinalIgnoreCase) ||
|
||||
lastRoute.Contains("list", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return (int)LogOpType.QUERY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Ewide.Core.Util;
|
||||
using Ewide.Core.Attributes;
|
||||
using Ewide.Core.Util;
|
||||
using Furion;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
@@ -69,6 +70,7 @@ namespace Ewide.Core.Service
|
||||
/// <returns></returns>
|
||||
[HttpPost("/login")]
|
||||
[AllowAnonymous]
|
||||
[Op(LogOpType.GRANT)]
|
||||
public async Task<LoginOutput> LoginAsync([Required] LoginInput input)
|
||||
{
|
||||
var password = RSAHandler.RSADecrypt(input.Password);
|
||||
|
||||
Reference in New Issue
Block a user