mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
565d3249e5
Introduces OnlinePingingController and related integration/unit tests for user online status updates. Adds PingHandlerService with memory cache throttling, IPingHandlerService interface, and service registration. Implements VerifyFriendship service and interface for friendship validation, with exception handling. Refactors CurrentUserService for improved user ID extraction and testability. Updates ChatsHub to verify friendship before messaging. Cleans up MediaController and optimizes UsersRepository queries by removing unnecessary includes.
29 lines
836 B
C#
29 lines
836 B
C#
using System.Security.Claims;
|
|
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace Govor.Application.Infrastructure.Extensions;
|
|
|
|
public class CurrentUserService : ICurrentUserService
|
|
{
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
public CurrentUserService(IHttpContextAccessor httpContextAccessor)
|
|
{
|
|
_httpContextAccessor = httpContextAccessor;
|
|
}
|
|
|
|
public Guid GetCurrentUserId()
|
|
{
|
|
var user = _httpContextAccessor.HttpContext?.User;
|
|
var userIdClaim = user?.FindFirst("userId")?.Value;
|
|
|
|
if (string.IsNullOrEmpty(userIdClaim) || !Guid.TryParse(userIdClaim, out var userId))
|
|
{
|
|
throw new UnauthorizedAccessException("userID claim is missing or invalid");
|
|
}
|
|
|
|
return userId;
|
|
}
|
|
}
|