refactor(HomeController): Statische Eigenschaften SmsTotpStep und SmsFormat hinzugefügt.
This commit is contained in:
parent
80f9107e4e
commit
be44f9f436
@ -24,9 +24,9 @@ using EnvelopeGenerator.Application.Extensions;
|
|||||||
namespace EnvelopeGenerator.Web.Controllers
|
namespace EnvelopeGenerator.Web.Controllers
|
||||||
{
|
{
|
||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<HomeController> _logger;
|
private readonly ILogger<HomeController> _logger;
|
||||||
private readonly EnvelopeOldService envelopeOldService;
|
private readonly EnvelopeOldService envelopeOldService;
|
||||||
private readonly IEnvelopeReceiverService _envRcvService;
|
private readonly IEnvelopeReceiverService _envRcvService;
|
||||||
private readonly IEnvelopeHistoryService _historyService;
|
private readonly IEnvelopeHistoryService _historyService;
|
||||||
private readonly IStringLocalizer<Resource> _localizer;
|
private readonly IStringLocalizer<Resource> _localizer;
|
||||||
@ -38,6 +38,8 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
private readonly IMessagingService _msgService;
|
private readonly IMessagingService _msgService;
|
||||||
private readonly ICodeGenerator _codeGenerator;
|
private readonly ICodeGenerator _codeGenerator;
|
||||||
private readonly IReceiverService _rcvService;
|
private readonly IReceiverService _rcvService;
|
||||||
|
private static readonly int SmsTotpStep = 60 * 3;
|
||||||
|
private static readonly string SmsFormat = "{0}";
|
||||||
|
|
||||||
public HomeController(EnvelopeOldService envelopeOldService, ILogger<HomeController> logger, IEnvelopeReceiverService envelopeReceiverService, IEnvelopeHistoryService historyService, IStringLocalizer<Resource> localizer, IConfiguration configuration, HtmlSanitizer sanitizer, Cultures cultures, IEnvelopeMailService envelopeMailService, IEnvelopeReceiverReadOnlyService readOnlyService, IMessagingService messagingService, ICodeGenerator codeGenerator, IReceiverService receiverService)
|
public HomeController(EnvelopeOldService envelopeOldService, ILogger<HomeController> logger, IEnvelopeReceiverService envelopeReceiverService, IEnvelopeHistoryService historyService, IStringLocalizer<Resource> localizer, IConfiguration configuration, HtmlSanitizer sanitizer, Cultures cultures, IEnvelopeMailService envelopeMailService, IEnvelopeReceiverReadOnlyService readOnlyService, IMessagingService messagingService, ICodeGenerator codeGenerator, IReceiverService receiverService)
|
||||||
{
|
{
|
||||||
@ -72,7 +74,7 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
|
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("EnvelopeKey/{envelopeReceiverId}")]
|
[HttpGet("EnvelopeKey/{envelopeReceiverId}")]
|
||||||
public async Task<IActionResult> MainAsync([FromRoute] string envelopeReceiverId, [FromQuery] string? culture = null)
|
public async Task<IActionResult> MainAsync([FromRoute] string envelopeReceiverId, [FromQuery] string? culture = null)
|
||||||
{
|
{
|
||||||
@ -195,9 +197,9 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
if (viaSms)
|
if (viaSms)
|
||||||
{
|
{
|
||||||
//add date time cache
|
//add date time cache
|
||||||
var res = await _msgService.SendSmsCodeAsync(er_secret.PhoneNumber!, er_secret.Receiver.TotpSecretkey);
|
var res = await _msgService.SendSmsCodeAsync(er_secret.PhoneNumber!, er_secret.Receiver!.TotpSecretkey!, SmsFormat);
|
||||||
if (res.Ok)
|
if (res.Ok)
|
||||||
return View("EnvelopeLocked").WithData("CodeType", "smsCode").WithData("SmsExpiration", res.Expiration);
|
return View("EnvelopeLocked").WithData("CodeType", "smsCode").WithData("SmsExpiration", _codeGenerator.GetTotpExpirationTime(SmsTotpStep));
|
||||||
else if (!res.Allowed)
|
else if (!res.Allowed)
|
||||||
return View("EnvelopeLocked").WithData("CodeType", "smsCode").WithData("SmsExpiration", res.AllowedAt);
|
return View("EnvelopeLocked").WithData("CodeType", "smsCode").WithData("SmsExpiration", res.AllowedAt);
|
||||||
else
|
else
|
||||||
@ -246,14 +248,14 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
}
|
}
|
||||||
return await TFAView(auth.UserSelectSMS);
|
return await TFAView(auth.UserSelectSMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (auth.HasSmsCode)
|
else if (auth.HasSmsCode)
|
||||||
{
|
{
|
||||||
if (er_secret.Receiver!.TotpSecretkey is null)
|
if (er_secret.Receiver!.TotpSecretkey is null)
|
||||||
throw new InvalidOperationException($"TotpSecretkey of DTO cannot validate without TotpSecretkey. Dto: {JsonConvert.SerializeObject(er_secret)}");
|
throw new InvalidOperationException($"TotpSecretkey of DTO cannot validate without TotpSecretkey. Dto: {JsonConvert.SerializeObject(er_secret)}");
|
||||||
|
|
||||||
if (_codeGenerator.VerifyTotp(auth.SmsCode!, er_secret.Receiver.TotpSecretkey, step: 60 * 5))
|
if (_codeGenerator.VerifyTotp(auth.SmsCode!, er_secret.Receiver.TotpSecretkey, step: SmsTotpStep))
|
||||||
{
|
{
|
||||||
Response.StatusCode = StatusCodes.Status401Unauthorized;
|
Response.StatusCode = StatusCodes.Status401Unauthorized;
|
||||||
ViewData["ErrorMessage"] = _localizer[WebKey.WrongAccessCode].Value;
|
ViewData["ErrorMessage"] = _localizer[WebKey.WrongAccessCode].Value;
|
||||||
@ -279,14 +281,14 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
//continue the process without important data to minimize security errors.
|
//continue the process without important data to minimize security errors.
|
||||||
EnvelopeReceiverDto er = er_secret;
|
EnvelopeReceiverDto er = er_secret;
|
||||||
|
|
||||||
ViewData["EnvelopeKey"] = envelopeReceiverId;
|
ViewData["EnvelopeKey"] = envelopeReceiverId;
|
||||||
//check rejection
|
//check rejection
|
||||||
var rejRcvrs = await _historyService.ReadRejectingReceivers(er.Envelope!.Id);
|
var rejRcvrs = await _historyService.ReadRejectingReceivers(er.Envelope!.Id);
|
||||||
if(rejRcvrs.Any())
|
if(rejRcvrs.Any())
|
||||||
{
|
{
|
||||||
ViewBag.IsExt = !rejRcvrs.Contains(er.Receiver); //external if the current user is not rejected
|
ViewBag.IsExt = !rejRcvrs.Contains(er.Receiver); //external if the current user is not rejected
|
||||||
return View("EnvelopeRejected", er);
|
return View("EnvelopeRejected", er);
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if it has already signed
|
//check if it has already signed
|
||||||
if (await _historyService.IsSigned(envelopeId: er.Envelope!.Id, userReference: er.Receiver!.EmailAddress))
|
if (await _historyService.IsSigned(envelopeId: er.Envelope!.Id, userReference: er.Receiver!.EmailAddress))
|
||||||
@ -299,8 +301,8 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.LogEnvelopeError(envelopeReceiverId: envelopeReceiverId, message: "No document byte-data was found in ENVELOPE_DOCUMENT table.");
|
_logger.LogEnvelopeError(envelopeReceiverId: envelopeReceiverId, message: "No document byte-data was found in ENVELOPE_DOCUMENT table.");
|
||||||
return this.ViewDocumentNotFound();
|
return this.ViewDocumentNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
var claims = new List<Claim> {
|
var claims = new List<Claim> {
|
||||||
new(ClaimTypes.NameIdentifier, uuid),
|
new(ClaimTypes.NameIdentifier, uuid),
|
||||||
@ -326,7 +328,7 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
//add PSPDFKit licence key
|
//add PSPDFKit licence key
|
||||||
ViewData["PSPDFKitLicenseKey"] = _configuration["PSPDFKitLicenseKey"];
|
ViewData["PSPDFKitLicenseKey"] = _configuration["PSPDFKitLicenseKey"];
|
||||||
|
|
||||||
return View("ShowEnvelope", er);
|
return View("ShowEnvelope", er);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -381,7 +383,8 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
return await _envRcvService.ReadByEnvelopeReceiverIdAsync(envelopeReceiverId).ThenAsync(
|
return await _envRcvService.ReadByEnvelopeReceiverIdAsync(envelopeReceiverId).ThenAsync(
|
||||||
SuccessAsync: async (er) =>
|
SuccessAsync: async (er) =>
|
||||||
{ViewData["UserCulture"] = _cultures[UserLanguage];
|
{
|
||||||
|
ViewData["UserCulture"] = _cultures[UserLanguage];
|
||||||
ViewData["UserCulture"] = _cultures[UserLanguage];
|
ViewData["UserCulture"] = _cultures[UserLanguage];
|
||||||
return await _historyService.IsRejected(envelopeId: er.EnvelopeId)
|
return await _historyService.IsRejected(envelopeId: er.EnvelopeId)
|
||||||
? View(er)
|
? View(er)
|
||||||
@ -434,7 +437,7 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
SuccessAsync: async er =>
|
SuccessAsync: async er =>
|
||||||
{
|
{
|
||||||
var envelopeKey = (er.Envelope!.Uuid, er.Receiver!.Signature).EncodeEnvelopeReceiverId();
|
var envelopeKey = (er.Envelope!.Uuid, er.Receiver!.Signature).EncodeEnvelopeReceiverId();
|
||||||
|
|
||||||
EnvelopeResponse response = await envelopeOldService.LoadEnvelope(envelopeKey);
|
EnvelopeResponse response = await envelopeOldService.LoadEnvelope(envelopeKey);
|
||||||
|
|
||||||
//TODO: implement multi-threading to history process (Task)
|
//TODO: implement multi-threading to history process (Task)
|
||||||
@ -514,7 +517,7 @@ namespace EnvelopeGenerator.Web.Controllers
|
|||||||
var cookieValue = Request.Cookies[CookieRequestCultureProvider.DefaultCookieName];
|
var cookieValue = Request.Cookies[CookieRequestCultureProvider.DefaultCookieName];
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(cookieValue))
|
if (string.IsNullOrEmpty(cookieValue))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var culture = CookieRequestCultureProvider.ParseCookieValue(cookieValue)?.Cultures[0];
|
var culture = CookieRequestCultureProvider.ParseCookieValue(cookieValue)?.Cultures[0];
|
||||||
return culture?.Value ?? null;
|
return culture?.Value ?? null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user