This commit is contained in:
2026-11-13 13:47:53 +03:30
parent 2b7209c5fb
commit 3e57ed6af9
9 changed files with 185 additions and 64 deletions
+1
View File
@@ -14,6 +14,7 @@ namespace xBotService.Providers.GraphQL
Field(x => x.BotLastname);
Field(x => x.BotFirstname);
Field(x => x.LastVerificationSent);
Field(x => x.ShownVirificationMenu);
}
}
}
+52 -27
View File
@@ -15,6 +15,8 @@ using xIdentityService.Interfaces;
using Microsoft.Extensions.Logging;
using xExceptions.Constants;
using System;
using xBotService.Models.Dtos;
using xIdentityService.Security;
namespace xBotService.Providers
{
@@ -22,12 +24,14 @@ namespace xBotService.Providers
{
//
private readonly ILogger<XBotProvider> logger;
private readonly IXSecurityProvider securityProvider;
private readonly IXIdentityHttpProvider httpProvider;
private readonly XValidationProvider validationProvider;
private readonly XBotServiceConfiguration configuration;
public XBotProvider(
ILogger<XBotProvider> logger,
IXSecurityProvider securityProvider,
IXIdentityHttpProvider httpProvider,
XValidationProvider validationProvider,
XBotServiceConfiguration configuration
@@ -35,6 +39,7 @@ namespace xBotService.Providers
{
//
this.logger = logger;
this.securityProvider = securityProvider;
this.httpProvider = httpProvider;
this.configuration = configuration;
this.validationProvider = validationProvider;
@@ -270,7 +275,7 @@ namespace xBotService.Providers
ReplyMarkup = markup.ReplyMarkup,
Text = XBotMessageIds.XBotRequestVerificationCodeMessageText,
};
//
var result = await SendMessage(
requestModel: requestModel,
@@ -284,36 +289,56 @@ namespace xBotService.Providers
/// <summary>
/// Send Verification Code to Requests ...
/// </summary>
/// <param name="chatId"></param>
/// <param name="code"></param>
/// <param name="ttlSeconds"></param>
/// <param name="botUser"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
// public virtual async Task<XBotMessageResponse> SendVerificationCode(
// long chatId,
// string code,
// int ttlSeconds,
// CancellationToken cancellationToken = default
// )
// {
// //
// // Validate ...
// if (chatId <= 0 || ttlSeconds < 60 || code.IsNullOrEmpty())
// {
// XException.InvalidArgs.Throw();
// }
public virtual async Task<XBotMessage> SendVerificationCode(
XBotUserDto botUser,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
if (
botUser.IsNullOrDefault() ||
botUser.BotUserId <= 0)
{
XException.InvalidArgs.Throw();
}
// //
// var minutes = ttlSeconds / 60;
// var response = await SendMessage(
// chatId: chatId,
// cancellationToken: cancellationToken,
// text: $"✅ کد وریفیکیشن شما:\n\n<code>{code}</code>\n\n⏱ این کد تا {minutes} دقیقه معتبر است."
// );
//
// Check User not Verified ...
if (botUser.VerifiedOn.HasValue)
{
XException.NotAllowed.Throw();
}
// //
// return response;
// }
//
var code = securityProvider
.Encrypt(botUser.BotUserId.ToString())
.ToMd5String();
//
var message = XBotMessageIds.XBotVerificationCodeMessageText
.ApplyTemplates(new Dictionary<string, string>
{
{ XBotParams.XVerificationTokenParam, code },
{ XBotParams.XTTLInMinuteParam, configuration.VerificationCodeTTL.ToString() },
});
//
var response = await SendMessage(
cancellationToken: cancellationToken,
requestModel: new XBotSendMessageRequest
{
Text = message,
ChatId = botUser.BotUserId,
}
);
//
return response;
}
/// <summary>
/// an Accept for Exit Loading on Bot ...