- Introduced Telegram.Bot package for bot functionality. - Updated user management to include Telegram linking and blocking features. - Enhanced activation request handling with notifications via Telegram. - Added new database entities for Telegram link tokens and login requests. - Implemented traffic synchronization for client stats in the XuiPanelGateway. - Updated application structure to support new test projects and improved dependency injection for Telegram services.
31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
using System.Security.Claims;
|
||
using Microsoft.AspNetCore.Http;
|
||
using PnvPanel.Application.Common.Interfaces;
|
||
|
||
namespace PnvPanel.Infrastructure.Identity;
|
||
|
||
/// <summary>
|
||
/// В HTTP-запросах читает JWT-claims. В Telegram-боте (нет HttpContext) вызывающая сторона
|
||
/// заранее задаёт пользователя через ICurrentUserSetter.SetUser(...) в рамках DI-scope апдейта.
|
||
/// </summary>
|
||
internal sealed class CurrentUser(IHttpContextAccessor httpContextAccessor) : ICurrentUser, ICurrentUserSetter
|
||
{
|
||
private (Guid Id, string Name)? _override;
|
||
|
||
private ClaimsPrincipal? Principal => httpContextAccessor.HttpContext?.User;
|
||
|
||
public Guid? UserId => _override?.Id ?? ParseHttpUserId();
|
||
|
||
public string? UserName => _override?.Name ?? Principal?.FindFirstValue(ClaimTypes.Name);
|
||
|
||
public bool IsAuthenticated => _override is not null || (Principal?.Identity?.IsAuthenticated ?? false);
|
||
|
||
public void SetUser(Guid userId, string userName) => _override = (userId, userName);
|
||
|
||
private Guid? ParseHttpUserId()
|
||
{
|
||
var value = Principal?.FindFirstValue(ClaimTypes.NameIdentifier);
|
||
return Guid.TryParse(value, out var id) ? id : null;
|
||
}
|
||
}
|