This commit is contained in:
@@ -63,5 +63,17 @@ namespace IRaCIS.Core.Domain.Share
|
||||
string BrowserFingerprint { get; }
|
||||
|
||||
UserWorkLanguage UserWorkLanguage { get; }
|
||||
|
||||
|
||||
ClientInfo ClientInfo { get; }
|
||||
}
|
||||
|
||||
public class ClientInfo
|
||||
{
|
||||
public string Browser { get; set; }
|
||||
public string OS { get; set; }
|
||||
public string DeviceType { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using UAParser;
|
||||
|
||||
namespace IRaCIS.Core.Domain.Share
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户信息
|
||||
/// </summary>
|
||||
public class UserInfo : IUserInfo
|
||||
public class UserInfo(IHttpContextAccessor _accessor, Parser parser) : IUserInfo
|
||||
{
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
|
||||
public UserInfo(IHttpContextAccessor accessor)
|
||||
{
|
||||
_accessor = accessor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户角色Id
|
||||
@@ -348,6 +344,55 @@ namespace IRaCIS.Core.Domain.Share
|
||||
|
||||
}
|
||||
|
||||
public ClientInfo ClientInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
var userAgent = _accessor?.HttpContext.Request.Headers["User-Agent"].ToString();
|
||||
|
||||
if (!string.IsNullOrEmpty(userAgent))
|
||||
{
|
||||
var clientInfo = parser.Parse(userAgent);
|
||||
|
||||
return new ClientInfo()
|
||||
{
|
||||
OS = clientInfo.OS.ToString(),
|
||||
Browser = clientInfo.UA.ToString(),
|
||||
DeviceType = userAgent.Contains("Mobile") ? "Mobile" : "Desktop"
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return new ClientInfo()
|
||||
{
|
||||
OS = "Unknown",
|
||||
Browser = "Unknown",
|
||||
DeviceType = "Unknown"
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
return new ClientInfo()
|
||||
{
|
||||
OS = "ParseError",
|
||||
Browser = "ParseError",
|
||||
DeviceType = "ParseError"
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Guid? SignId
|
||||
{
|
||||
@@ -417,7 +462,7 @@ namespace IRaCIS.Core.Domain.Share
|
||||
|
||||
public const string PermissionStr = "permissionStr";
|
||||
|
||||
public const string UserWorkLanguage = "userWorkLanguage";
|
||||
public const string UserWorkLanguage = "userWorkLanguage";
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="UAParser" Version="3.1.47" />
|
||||
<PackageReference Include="EFCore.BulkExtensions" Version="10.0.1" />
|
||||
<PackageReference Include="EntityFrameworkCore.Triggered" Version="3.2.2" />
|
||||
<PackageReference Include="EntityFrameworkCore.Projectables" Version="6.0.5" />
|
||||
|
||||
Reference in New Issue
Block a user