feat(TFARegController): Try-Catch zur Methode reg'e hinzugefügt.
- Ausnahme ist so eingestellt, dass sie protokolliert wird.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -197,12 +197,11 @@ public class HomeController : ViewControllerBase
|
||||
if (er_secret.Envelope!.TFAEnabled)
|
||||
{
|
||||
var rcv = er_secret.Receiver;
|
||||
if (rcv.IsTotpSecretInvalid())
|
||||
if (rcv.TotpSecretkey is null)
|
||||
{
|
||||
rcv.TotpSecretkey = _authenticator.GenerateTotpSecretKey();
|
||||
rcv.TotpExpiration = DateTime.Now.AddMonths(1);
|
||||
await _rcvService.UpdateAsync(rcv);
|
||||
await _mailService.SendTFAQrCodeAsync(er_secret);
|
||||
}
|
||||
return await TFAViewAsync(auth.UserSelectSMS, er_secret, envelopeReceiverId);
|
||||
}
|
||||
@@ -229,7 +228,7 @@ public class HomeController : ViewControllerBase
|
||||
[NonAction]
|
||||
private async Task<IActionResult?> HandleAuthenticatorAsync(Auth auth, EnvelopeReceiverSecretDto er_secret, string envelopeReceiverId)
|
||||
{
|
||||
if (er_secret.Receiver!.IsTotpInvalid(totp: auth.AuthenticatorCode!))
|
||||
if (er_secret.Receiver!.TotpSecretkey is null)
|
||||
{
|
||||
Response.StatusCode = StatusCodes.Status401Unauthorized;
|
||||
ViewData["ErrorMessage"] = _localizer[WebKey.WrongAccessCode].Value;
|
||||
|
||||
@@ -30,6 +30,8 @@ public class TFARegController : ViewControllerBase
|
||||
|
||||
[HttpGet("{envelopeReceiverId}")]
|
||||
public async Task<IActionResult> Reg(string envelopeReceiverId)
|
||||
{
|
||||
try
|
||||
{
|
||||
envelopeReceiverId = _sanitizer.Sanitize(envelopeReceiverId);
|
||||
(string? uuid, string? signature) = envelopeReceiverId.DecodeEnvelopeReceiverId();
|
||||
@@ -75,4 +77,10 @@ public class TFARegController : ViewControllerBase
|
||||
|
||||
return View();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.LogEnvelopeError(envelopeReceiverId: envelopeReceiverId, exception: ex, message: _localizer[WebKey.UnexpectedError]);
|
||||
return this.ViewInnerServiceError();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@
|
||||
</div>
|
||||
<h1>@_localizer[WebKey.Formats.LockedTitle.Format(codeKeyName)]</h1>
|
||||
</header>
|
||||
@if (tfaRegDeadline is not null && tfaRegDeadline > DateTime.Now)
|
||||
@if (viaAuthenticator && (tfaRegDeadline is null || tfaRegDeadline > DateTime.Now))
|
||||
{
|
||||
<section class="text-center">
|
||||
<p class="m-0 p-0">
|
||||
|
||||
Reference in New Issue
Block a user