feat(TFARegController): Try-Catch zur Methode reg'e hinzugefügt.

- Ausnahme ist so eingestellt, dass sie protokolliert wird.
This commit is contained in:
Developer 02
2025-02-06 19:31:50 +01:00
parent 95785e8c8b
commit 9cdb1409c0
4 changed files with 45 additions and 60 deletions

View File

@@ -1,22 +0,0 @@
using EnvelopeGenerator.Application.DTOs.Receiver;
using EnvelopeGenerator.Extensions;
using Newtonsoft.Json;
namespace EnvelopeGenerator.Application.Extensions
{
public static class DTOExtensions
{
public static bool IsTotpSecretExpired(this ReceiverReadDto dto, int minutesBeforeExpiration = 30)
=> dto.TotpExpiration < DateTime.Now.AddMinutes(minutesBeforeExpiration * -1);
public static bool IsTotpSecretInvalid(this ReceiverReadDto dto, int minutesBeforeExpiration = 30)
=> dto.IsTotpSecretExpired(minutesBeforeExpiration) || dto.TotpSecretkey is null;
public static bool IsTotpSecretValid(this ReceiverReadDto dto, int minutesBeforeExpiration = 30)
=> !dto.IsTotpSecretInvalid(minutesBeforeExpiration);
public static bool IsTotpValid(this ReceiverReadDto dto, string totp) => dto.TotpSecretkey is null ? throw new ArgumentNullException(nameof(dto), $"TotpSecretkey of DTO cannot validate without TotpSecretkey. Dto: {JsonConvert.SerializeObject(dto)}") : totp.IsValidTotp(dto.TotpSecretkey);
public static bool IsTotpInvalid(this ReceiverReadDto dto, string totp) => !dto.IsTotpValid(totp: totp);
}
}