- 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.
25 lines
956 B
C#
25 lines
956 B
C#
using PnvPanel.Application.Auth;
|
|
using PnvPanel.Application.Common.Interfaces;
|
|
using PnvPanel.Application.Common.Messaging;
|
|
using PnvPanel.Application.Common.Models;
|
|
using PnvPanel.Domain.Telegram;
|
|
|
|
namespace PnvPanel.Application.Telegram;
|
|
|
|
public sealed class CreateLinkTokenCommandHandler(IAppDbContext dbContext, ICurrentUser currentUser)
|
|
: ICommandHandler<CreateLinkTokenCommand, Result<LinkTokenDto>>
|
|
{
|
|
private static readonly TimeSpan Ttl = TimeSpan.FromMinutes(5);
|
|
|
|
public Task<Result<LinkTokenDto>> Handle(CreateLinkTokenCommand command, CancellationToken cancellationToken)
|
|
{
|
|
if (currentUser.UserId is not { } userId)
|
|
return Task.FromResult(Result.Failure<LinkTokenDto>(AuthErrors.Unauthorized));
|
|
|
|
var token = TelegramLinkToken.Create(userId, Ttl);
|
|
dbContext.TelegramLinkTokens.Add(token);
|
|
|
|
return Task.FromResult(Result.Success(new LinkTokenDto(token.Token, token.ExpiresAt)));
|
|
}
|
|
}
|