feat:添加登录事件

This commit is contained in:
陈淳
2023-04-19 18:06:40 +08:00
parent 2fd861025a
commit a93e65df0a
6 changed files with 66 additions and 68 deletions

View File

@@ -1,5 +1,8 @@
using System;
using IPTools.Core;
using SqlSugar;
using UAParser;
using Yi.Framework.Infrastructure.AspNetCore;
using Yi.Framework.Infrastructure.Data.Auditing;
using Yi.Framework.Infrastructure.Ddd.Entities;
@@ -45,4 +48,45 @@ namespace Yi.Furion.Core.Rbac.Entities
public long? CreatorId { get; set; }
}
public static class LoginLogEntityExtensions {
/// <summary>
/// 记录用户登陆信息
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public static LoginLogEntity GetLoginLogInfo(this HttpContext context)
{
ClientInfo GetClientInfo(HttpContext context)
{
var str = context.GetUserAgent();
var uaParser = Parser.GetDefault();
ClientInfo c = uaParser.Parse(str);
return c;
}
var ipAddr = context.GetClientIp();
IpInfo location;
if (ipAddr == "127.0.0.1")
{
location = new IpInfo() { Province = "本地", City = "本机" };
}
else
{
location = IpTool.Search(ipAddr);
}
ClientInfo clientInfo = GetClientInfo(context);
LoginLogEntity entity = new()
{
Browser = clientInfo.Device.Family,
Os = clientInfo.OS.ToString(),
LoginIp = ipAddr,
LoginLocation = location.Province + "-" + location.City
};
return entity;
}
}
}

View File

@@ -5,6 +5,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Furion.EventBus;
using Yi.Furion.Core.Rbac.Entities;
namespace Yi.Furion.Core.Rbac.Etos
{
@@ -28,6 +29,6 @@ namespace Yi.Furion.Core.Rbac.Etos
public long UserId { get; set; }
public string UserName { get; set; }
public HttpContext httpContext { get; set; }
public LoginLogEntity LoginLogEntity { get; set; }
}
}

View File

@@ -506,6 +506,13 @@
登录信息
</summary>
</member>
<member name="M:Yi.Furion.Core.Rbac.Entities.LoginLogEntityExtensions.GetLoginLogInfo(Microsoft.AspNetCore.Http.HttpContext)">
<summary>
记录用户登陆信息
</summary>
<param name="context"></param>
<returns></returns>
</member>
<member name="T:Yi.Furion.Core.Rbac.Entities.MenuEntity">
<summary>
菜单表