Revert "1"

This reverts commit 8ed1c958af.
This commit is contained in:
陈淳
2023-04-19 18:08:38 +08:00
parent 8ed1c958af
commit e904c3df69

View File

@@ -39,7 +39,7 @@ namespace Yi.Furion.Application.Rbac.SignalRHub
public override Task OnConnectedAsync() public override Task OnConnectedAsync()
{ {
var name = _currentUser.UserName; var name = _currentUser.UserName;
var loginUser = _httpContext.GetLoginLogInfo(); var loginUser = GetLoginLogInfo(_httpContext);
var user = clientUsers.Any(u => u.ConnnectionId == Context.ConnectionId); var user = clientUsers.Any(u => u.ConnnectionId == Context.ConnectionId);
//判断用户是否存在,否则添加集合 //判断用户是否存在,否则添加集合
if (!user) if (!user)
@@ -89,5 +89,46 @@ namespace Yi.Furion.Application.Rbac.SignalRHub
await Clients.All.SendAsync("ReceiveAllInfo", test); await Clients.All.SendAsync("ReceiveAllInfo", test);
} }
/// <summary>
/// 获取客户端信息
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private static ClientInfo GetClientInfo(HttpContext context)
{
var str = context.GetUserAgent();
var uaParser = Parser.GetDefault();
ClientInfo c = uaParser.Parse(str);
return c;
}
/// <summary>
/// 记录用户登陆信息
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private static LoginLogEntity GetLoginLogInfo(HttpContext context)
{
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;
}
} }
} }