From 241991721dfedf269394f7955086f42a0476adbb Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Wed, 11 Dec 2024 18:42:23 +0100 Subject: [PATCH] =?UTF-8?q?feat(DTOExtension):=20Erweiterungsmethode=20hin?= =?UTF-8?q?zugef=C3=BCgt,=20um=20totp=20direkt=20=C3=BCber=20Receiver=20zu?= =?UTF-8?q?=20pr=C3=BCfen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EnvelopeGenerator.Application/Extensions/DTOExtensions.cs | 6 ++++++ EnvelopeGenerator.Web/Controllers/HomeController.cs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/EnvelopeGenerator.Application/Extensions/DTOExtensions.cs b/EnvelopeGenerator.Application/Extensions/DTOExtensions.cs index 8c88b34f..f1cd28ca 100644 --- a/EnvelopeGenerator.Application/Extensions/DTOExtensions.cs +++ b/EnvelopeGenerator.Application/Extensions/DTOExtensions.cs @@ -1,4 +1,6 @@ using EnvelopeGenerator.Application.DTOs.Receiver; +using EnvelopeGenerator.Extensions; +using Newtonsoft.Json; namespace EnvelopeGenerator.Application.Extensions { @@ -12,5 +14,9 @@ namespace EnvelopeGenerator.Application.Extensions 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); } } \ No newline at end of file diff --git a/EnvelopeGenerator.Web/Controllers/HomeController.cs b/EnvelopeGenerator.Web/Controllers/HomeController.cs index 1dacd4e0..aa7b8ea8 100644 --- a/EnvelopeGenerator.Web/Controllers/HomeController.cs +++ b/EnvelopeGenerator.Web/Controllers/HomeController.cs @@ -258,7 +258,7 @@ namespace EnvelopeGenerator.Web.Controllers } else if (auth.HasAuthenticatorCode) { - if (!auth.AuthenticatorCode!.IsValidTotp(er_secret.Receiver!.TotpSecretkey!)) + if (er_secret.Receiver!.IsTotpInvalid(totp: auth.AuthenticatorCode!)) { Response.StatusCode = StatusCodes.Status401Unauthorized; ViewData["ErrorMessage"] = _localizer[WebKey.WrongAccessCode].Value;