Add Telegram bot integration and enhance user management features
- 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.
This commit is contained in:
@@ -4,20 +4,27 @@ using PnvPanel.Application.Common.Interfaces;
|
||||
|
||||
namespace PnvPanel.Infrastructure.Identity;
|
||||
|
||||
internal sealed class CurrentUser(IHttpContextAccessor httpContextAccessor) : ICurrentUser
|
||||
/// <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
|
||||
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()
|
||||
{
|
||||
get
|
||||
{
|
||||
var value = Principal?.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Guid.TryParse(value, out var id) ? id : null;
|
||||
}
|
||||
var value = Principal?.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Guid.TryParse(value, out var id) ? id : null;
|
||||
}
|
||||
|
||||
public string? UserName => Principal?.FindFirstValue(ClaimTypes.Name);
|
||||
|
||||
public bool IsAuthenticated => Principal?.Identity?.IsAuthenticated ?? false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user