feat(api): UserProfile
This commit is contained in:
@@ -13,13 +13,21 @@ namespace PARR.API.Services.Implementations
|
||||
private readonly IUserService userService;
|
||||
private readonly IHostService hostService;
|
||||
private readonly UserCacheSettings userCacheSettings;
|
||||
private readonly IClientService clientService;
|
||||
|
||||
public AuthService(IRedisCacheService cacheService, IUserService userService, IHostService hostService, UserCacheSettings userCacheSettings)
|
||||
public AuthService(
|
||||
IRedisCacheService cacheService,
|
||||
IUserService userService,
|
||||
IHostService hostService,
|
||||
UserCacheSettings userCacheSettings,
|
||||
IClientService clientService
|
||||
)
|
||||
{
|
||||
this.cacheService = cacheService;
|
||||
this.userService = userService;
|
||||
this.hostService = hostService;
|
||||
this.userCacheSettings = userCacheSettings;
|
||||
this.clientService = clientService;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +40,17 @@ namespace PARR.API.Services.Implementations
|
||||
}
|
||||
|
||||
|
||||
public async Task<UserCache?> GetCurrentUserAsync()
|
||||
{
|
||||
var userIp = clientService.GetClientIp()?.ToString();
|
||||
|
||||
if (userIp == null)
|
||||
return null;
|
||||
|
||||
return await GetUserAsync(userIp);
|
||||
}
|
||||
|
||||
|
||||
public async Task<UserCache?> GetUserAsync(string ipAddress)
|
||||
{
|
||||
// смотрим, есть ли в кэше
|
||||
@@ -82,12 +101,18 @@ namespace PARR.API.Services.Implementations
|
||||
};
|
||||
|
||||
if (host != null)
|
||||
{
|
||||
cacheData.Name = host.Ek;
|
||||
cacheData.HostId = host.Id;
|
||||
cacheData.LastLogon = host.LastLogon;
|
||||
}
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
cacheData.Name = user.Name + (host != null ? $", {host.Ek}" : string.Empty);
|
||||
cacheData.Description = user.Description ?? string.Empty;
|
||||
cacheData.UserId = user.Id;
|
||||
cacheData.LastLogon = user.LastLogon;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,5 +32,11 @@ namespace PARR.API.Services.Interfaces
|
||||
/// <param name="ipAddress"></param>
|
||||
/// <returns></returns>
|
||||
Task UnlockUserAsync(string ipAddress);
|
||||
|
||||
/// <summary>
|
||||
/// Получить текущего пользователя
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<UserCache?> GetCurrentUserAsync();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user