fix(EnvelopeSmsHandler): Korrekte Ablaufprüfung und Cache-Aktualisierung in SendTotpAsync
- Die Bedingung für die Überprüfung des Ablaufs wurde korrigiert, so dass sie korrekt null zurückgibt, wenn der gespeicherte Ablauf in der Zukunft liegt. - Fehlende Cache-Aktualisierung zur Speicherung des neuen Verfallsdatums nach dem Versand der TOTP-SMS hinzugefügt.
This commit is contained in:
parent
20825aa3ea
commit
5f780f8d1e
@ -37,13 +37,14 @@ public class EnvelopeSmsHandler : IEnvelopeSmsHandler
|
|||||||
var key = string.Format(_totpSmsParams.Expiration.CacheKeyFormat, er_secret.EnvelopeId, er_secret.ReceiverId);
|
var key = string.Format(_totpSmsParams.Expiration.CacheKeyFormat, er_secret.EnvelopeId, er_secret.ReceiverId);
|
||||||
var expiration = await _dCache.GetDateTimeAsync(key, cToken);
|
var expiration = await _dCache.GetDateTimeAsync(key, cToken);
|
||||||
|
|
||||||
if(expiration is DateTime expirationDateTime && expirationDateTime < DateTime.Now)
|
if(expiration is DateTime expirationDateTime && expirationDateTime >= DateTime.Now)
|
||||||
return (null, expirationDateTime);
|
return (null, expirationDateTime);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var new_expiration = DateTime.Now.AddSeconds(_totpSmsParams.TotpStep);
|
var new_expiration = DateTime.Now.AddSeconds(_totpSmsParams.TotpStep);
|
||||||
var totp = _authenticator.GenerateTotp(er_secret.Receiver!.TotpSecretkey!, _totpSmsParams.TotpStep);
|
var totp = _authenticator.GenerateTotp(er_secret.Receiver!.TotpSecretkey!, _totpSmsParams.TotpStep);
|
||||||
var msg = string.Format(_totpSmsParams.Format, totp, new_expiration.ToString(_totpSmsParams.Expiration.Format, _totpSmsParams.Expiration.CultureInfo));
|
var msg = string.Format(_totpSmsParams.Format, totp, new_expiration.ToString(_totpSmsParams.Expiration.Format, _totpSmsParams.Expiration.CultureInfo));
|
||||||
|
await _dCache.SetDateTimeAsync(key, new_expiration, cToken: cToken);
|
||||||
return (await _sender.SendSmsAsync(er_secret.PhoneNumber!, msg), new_expiration);
|
return (await _sender.SendSmsAsync(er_secret.PhoneNumber!, msg), new_expiration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -160,7 +160,7 @@ public class HomeController : ViewControllerBase
|
|||||||
{
|
{
|
||||||
var (smsRes, expiration) = await _envSmsHandler.SendTotpAsync(er_secret);
|
var (smsRes, expiration) = await _envSmsHandler.SendTotpAsync(er_secret);
|
||||||
|
|
||||||
if (smsRes is not null && smsRes.Failed)
|
if (smsRes?.Failed ?? false)
|
||||||
{
|
{
|
||||||
var res_json = JsonConvert.SerializeObject(smsRes);
|
var res_json = JsonConvert.SerializeObject(smsRes);
|
||||||
_logger.LogEnvelopeError(envelopeReceiverId: envelopeReceiverId, message: $"An unexpected error occurred while sending an SMS code. Response: ${res_json}");
|
_logger.LogEnvelopeError(envelopeReceiverId: envelopeReceiverId, message: $"An unexpected error occurred while sending an SMS code. Response: ${res_json}");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user