优化登录日志记录
This commit is contained in:
parent
283472b424
commit
e14182c883
@ -17,6 +17,8 @@ using Hei.Captcha;
|
|||||||
using ZR.Common;
|
using ZR.Common;
|
||||||
using ZR.Service.System;
|
using ZR.Service.System;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using UAParser;
|
||||||
|
using IPTools.Core;
|
||||||
|
|
||||||
namespace ZR.Admin.WebApi.Controllers.System
|
namespace ZR.Admin.WebApi.Controllers.System
|
||||||
{
|
{
|
||||||
@ -77,7 +79,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
return ToResponse(ResultCode.CAPTCHA_ERROR, "验证码错误");
|
return ToResponse(ResultCode.CAPTCHA_ERROR, "验证码错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = sysLoginService.Login(loginBody, AsyncFactory.RecordLogInfo(httpContextAccessor.HttpContext, "0", "login"));
|
var user = sysLoginService.Login(loginBody, RecordLogInfo(httpContextAccessor.HttpContext));
|
||||||
|
|
||||||
List<SysRole> roles = roleService.SelectUserRoleListByUserId(user.UserId);
|
List<SysRole> roles = roleService.SelectUserRoleListByUserId(user.UserId);
|
||||||
//权限集合 eg *:*:*,system:user:list
|
//权限集合 eg *:*:*,system:user:list
|
||||||
@ -178,5 +180,27 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
|
|
||||||
return ToJson(1, obj);
|
return ToJson(1, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 记录用户登陆信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public SysLogininfor RecordLogInfo(HttpContext context)
|
||||||
|
{
|
||||||
|
var ipAddr = context.GetClientUserIp();
|
||||||
|
var ip_info = IpTool.Search(ipAddr);
|
||||||
|
ClientInfo clientInfo = context.GetClientInfo();
|
||||||
|
SysLogininfor sysLogininfor = new()
|
||||||
|
{
|
||||||
|
browser = clientInfo.Device.Family,
|
||||||
|
os = clientInfo.OS.ToString(),
|
||||||
|
ipaddr = ipAddr,
|
||||||
|
userName = context.GetName(),
|
||||||
|
loginLocation = ip_info.Province + "-" + ip_info.City
|
||||||
|
};
|
||||||
|
|
||||||
|
return sysLogininfor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,34 +0,0 @@
|
|||||||
using IPTools.Core;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using UAParser;
|
|
||||||
using ZR.Admin.WebApi.Extensions;
|
|
||||||
using ZR.Model.System;
|
|
||||||
|
|
||||||
namespace ZR.Admin.WebApi.Framework
|
|
||||||
{
|
|
||||||
public class AsyncFactory
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 记录用户登陆信息
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context"></param>
|
|
||||||
/// <param name="status"></param>
|
|
||||||
/// <param name="message"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static SysLogininfor RecordLogInfo(HttpContext context, string status, string message)
|
|
||||||
{
|
|
||||||
ClientInfo clientInfo = context.GetClientInfo();
|
|
||||||
SysLogininfor sysLogininfor = new SysLogininfor();
|
|
||||||
sysLogininfor.browser = clientInfo.Device.Family;
|
|
||||||
sysLogininfor.os = clientInfo.OS.ToString();
|
|
||||||
sysLogininfor.ipaddr = context.GetClientUserIp();
|
|
||||||
sysLogininfor.msg = message;
|
|
||||||
sysLogininfor.userName = context.GetName();
|
|
||||||
sysLogininfor.status = status;
|
|
||||||
var ip_info = IpTool.Search(sysLogininfor.ipaddr);
|
|
||||||
sysLogininfor.loginLocation = ip_info.Province + "-" + ip_info.City;
|
|
||||||
|
|
||||||
return sysLogininfor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user