- 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.
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System.Security.Cryptography;
|
|
using PnvPanel.Domain.Common;
|
|
using PnvPanel.Domain.Exceptions;
|
|
|
|
namespace PnvPanel.Domain.Telegram;
|
|
|
|
/// <summary>Короткоживущий одноразовый токен для флоу привязки Telegram (deep-link в бота).</summary>
|
|
public sealed class TelegramLinkToken : Entity
|
|
{
|
|
public string Token { get; private set; } = string.Empty;
|
|
public Guid UserId { get; private set; }
|
|
public DateTimeOffset ExpiresAt { get; private set; }
|
|
public DateTimeOffset? ConsumedAt { get; private set; }
|
|
|
|
private TelegramLinkToken()
|
|
{
|
|
}
|
|
|
|
public static TelegramLinkToken Create(Guid userId, TimeSpan ttl)
|
|
{
|
|
return new TelegramLinkToken
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
Token = GenerateToken(),
|
|
UserId = userId,
|
|
ExpiresAt = DateTimeOffset.UtcNow.Add(ttl),
|
|
};
|
|
}
|
|
|
|
public bool IsValid => ConsumedAt is null && DateTimeOffset.UtcNow < ExpiresAt;
|
|
|
|
public void Consume()
|
|
{
|
|
if (!IsValid)
|
|
throw new DomainException("Токен привязки недействителен или уже использован.");
|
|
|
|
ConsumedAt = DateTimeOffset.UtcNow;
|
|
}
|
|
|
|
private static string GenerateToken() => Convert.ToHexString(RandomNumberGenerator.GetBytes(24)).ToLowerInvariant();
|
|
}
|