feat(HomeController): Aktualisiert, um SMS über zu senden.
- Unnötige Parameter in SmsParams entfernt. - Code-Sendefunktion von IMessagingService entfernt. - GetTotpExpirationTime Methode im CodeGenerator entfernt.
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
using DigitalData.Core.Abstractions.Client;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using OtpNet;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Configurations.GtxMessaging
|
||||
{
|
||||
/// <summary>
|
||||
@@ -20,11 +17,5 @@ namespace EnvelopeGenerator.Application.Configurations.GtxMessaging
|
||||
public string RecipientQueryParamName { get; init; } = "to";
|
||||
|
||||
public string MessageQueryParamName { get; init; } = "text";
|
||||
|
||||
public int CodeLength { get; init; } = 5;
|
||||
|
||||
public int SmsTotpStep { get; init; } = 300;
|
||||
|
||||
public string DefaultTotpMessageFormat { get; init; } = "{0}";
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,5 @@ namespace EnvelopeGenerator.Application.Contracts
|
||||
string GenerateTotp(string secretKey, int step = 30);
|
||||
|
||||
bool VerifyTotp(string totpCode, string secretKey, int step = 30, VerificationWindow? window = null);
|
||||
|
||||
bool GetTotpExpirationTime(int step = 30);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,4 @@ public interface IMessagingService
|
||||
string ServiceProvider { get; }
|
||||
|
||||
Task<SmsResponse> SendSmsAsync(string recipient, string message);
|
||||
|
||||
Task<SmsResponse> SendSmsCodeAsync(string recipient, string secretKey, string messageFormat = "{0}");
|
||||
}
|
||||
@@ -4,6 +4,8 @@
|
||||
{
|
||||
public required bool Ok { get; init; }
|
||||
|
||||
public bool Failed => !Ok;
|
||||
|
||||
public dynamic? Errors { get; init; }
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,6 @@ namespace EnvelopeGenerator.Application.Extensions
|
||||
services.AddHttpClientService<SmsParams>(smsConfigSection);
|
||||
services.TryAddSingleton<IMessagingService, GtxMessagingService>();
|
||||
services.TryAddSingleton<ICodeGenerator, CodeGenerator>();
|
||||
services.TryAddSingleton<IEnvelopeReceiverCache, EnvelopeReceiverCache>();
|
||||
services.TryAddSingleton<QRCodeGenerator>();
|
||||
|
||||
return services;
|
||||
|
||||
@@ -67,10 +67,5 @@ namespace EnvelopeGenerator.Application.Services
|
||||
|
||||
public bool VerifyTotp(string totpCode, string secretKey, int step = 30, VerificationWindow? window = null)
|
||||
=> new Totp(Base32Encoding.ToBytes(secretKey), step).VerifyTotp(totpCode, out _, window);
|
||||
|
||||
public bool GetTotpExpirationTime(int step = 30)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,17 +16,14 @@ public class GtxMessagingService : IMessagingService
|
||||
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
private readonly ICodeGenerator _codeGen;
|
||||
|
||||
public string ServiceProvider { get; }
|
||||
|
||||
public GtxMessagingService(IHttpClientService<SmsParams> smsClient, IOptions<SmsParams> smsParamsOptions, IMapper mapper, ICodeGenerator codeGenerator)
|
||||
public GtxMessagingService(IHttpClientService<SmsParams> smsClient, IOptions<SmsParams> smsParamsOptions, IMapper mapper)
|
||||
{
|
||||
_smsClient = smsClient;
|
||||
_smsParams = smsParamsOptions.Value;
|
||||
_mapper = mapper;
|
||||
ServiceProvider = GetType().Name.Replace("Service", string.Empty);
|
||||
_codeGen = codeGenerator;
|
||||
}
|
||||
|
||||
public async Task<SmsResponse> SendSmsAsync(string recipient, string message)
|
||||
@@ -39,11 +36,4 @@ public class GtxMessagingService : IMessagingService
|
||||
.ThenAsync(res => res.Json<GtxMessagingResponse>())
|
||||
.ThenAsync(_mapper.Map<SmsResponse>);
|
||||
}
|
||||
|
||||
public async Task<SmsResponse> SendSmsCodeAsync(string recipient, string secretKey, string? messageFormat = null)
|
||||
{
|
||||
var code = _codeGen.GenerateTotp(secretKey, _smsParams.SmsTotpStep);
|
||||
var message = string.Format(messageFormat ?? _smsParams.DefaultTotpMessageFormat, code);
|
||||
return await SendSmsAsync(recipient: recipient, message: message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user