diff --git a/EnvelopeGenerator.Application/Resource.cs b/EnvelopeGenerator.Application/Resources/Resource.cs similarity index 71% rename from EnvelopeGenerator.Application/Resource.cs rename to EnvelopeGenerator.Application/Resources/Resource.cs index 64b0bb3b..8b7e50aa 100644 --- a/EnvelopeGenerator.Application/Resource.cs +++ b/EnvelopeGenerator.Application/Resources/Resource.cs @@ -1,4 +1,4 @@ -namespace EnvelopeGenerator.Application +namespace EnvelopeGenerator.Application.Resources { /// /// The place holder class for Resource.*.resx diff --git a/EnvelopeGenerator.Application/Services/ConfigService.cs b/EnvelopeGenerator.Application/Services/ConfigService.cs index 4cb589fd..06cd4e8b 100644 --- a/EnvelopeGenerator.Application/Services/ConfigService.cs +++ b/EnvelopeGenerator.Application/Services/ConfigService.cs @@ -3,6 +3,7 @@ using DigitalData.Core.Application; using DigitalData.Core.DTO; using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.DTOs; +using EnvelopeGenerator.Application.Resources; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; using Microsoft.Extensions.Localization; diff --git a/EnvelopeGenerator.Application/Services/DocumentReceiverElementService.cs b/EnvelopeGenerator.Application/Services/DocumentReceiverElementService.cs index 6b1fc9bb..6f25514a 100644 --- a/EnvelopeGenerator.Application/Services/DocumentReceiverElementService.cs +++ b/EnvelopeGenerator.Application/Services/DocumentReceiverElementService.cs @@ -2,6 +2,7 @@ using DigitalData.Core.Application; using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.DTOs; +using EnvelopeGenerator.Application.Resources; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; using Microsoft.Extensions.Localization; diff --git a/EnvelopeGenerator.Application/Services/DocumentStatusService.cs b/EnvelopeGenerator.Application/Services/DocumentStatusService.cs index c175700e..3de05d6f 100644 --- a/EnvelopeGenerator.Application/Services/DocumentStatusService.cs +++ b/EnvelopeGenerator.Application/Services/DocumentStatusService.cs @@ -2,6 +2,7 @@ using DigitalData.Core.Application; using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.DTOs; +using EnvelopeGenerator.Application.Resources; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; using Microsoft.Extensions.Localization; diff --git a/EnvelopeGenerator.Application/Services/EmailOutService.cs b/EnvelopeGenerator.Application/Services/EmailOutService.cs index 45c29062..895f2f95 100644 --- a/EnvelopeGenerator.Application/Services/EmailOutService.cs +++ b/EnvelopeGenerator.Application/Services/EmailOutService.cs @@ -2,6 +2,7 @@ using DigitalData.Core.Application; using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.DTOs; +using EnvelopeGenerator.Application.Resources; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; using Microsoft.Extensions.Localization; diff --git a/EnvelopeGenerator.Application/Services/EmailTemplateService.cs b/EnvelopeGenerator.Application/Services/EmailTemplateService.cs index e03d0735..34f133f4 100644 --- a/EnvelopeGenerator.Application/Services/EmailTemplateService.cs +++ b/EnvelopeGenerator.Application/Services/EmailTemplateService.cs @@ -5,6 +5,7 @@ using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.DTOs; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; +using EnvelopeGenerator.Application.Resources; namespace EnvelopeGenerator.Application.Services { diff --git a/EnvelopeGenerator.Application/Services/EnvelopeCertificateService.cs b/EnvelopeGenerator.Application/Services/EnvelopeCertificateService.cs index 1aeb7bd9..807ba729 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeCertificateService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeCertificateService.cs @@ -5,6 +5,7 @@ using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.DTOs; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; +using EnvelopeGenerator.Application.Resources; namespace EnvelopeGenerator.Application.Services { diff --git a/EnvelopeGenerator.Application/Services/EnvelopeDocumentService.cs b/EnvelopeGenerator.Application/Services/EnvelopeDocumentService.cs index d9780511..36e880cc 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeDocumentService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeDocumentService.cs @@ -6,6 +6,7 @@ using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.DTOs; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; +using EnvelopeGenerator.Application.Resources; namespace EnvelopeGenerator.Application.Services { diff --git a/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs b/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs index 560e2eb0..fb8d3c77 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeHistoryService.cs @@ -6,6 +6,7 @@ using EnvelopeGenerator.Application.DTOs; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; using static EnvelopeGenerator.Common.Constants; +using EnvelopeGenerator.Application.Resources; namespace EnvelopeGenerator.Application.Services { diff --git a/EnvelopeGenerator.Application/Services/EnvelopeReceiverService.cs b/EnvelopeGenerator.Application/Services/EnvelopeReceiverService.cs index 3ab2b3f9..8c4b9567 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeReceiverService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeReceiverService.cs @@ -3,6 +3,7 @@ using DigitalData.Core.Application; using DigitalData.Core.DTO; using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.DTOs; +using EnvelopeGenerator.Application.Resources; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; using Microsoft.Extensions.Localization; diff --git a/EnvelopeGenerator.Application/Services/EnvelopeService.cs b/EnvelopeGenerator.Application/Services/EnvelopeService.cs index 8f746da3..82d69486 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeService.cs @@ -3,6 +3,7 @@ using DigitalData.Core.Application; using DigitalData.Core.DTO; using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.DTOs; +using EnvelopeGenerator.Application.Resources; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; using Microsoft.Extensions.Localization; diff --git a/EnvelopeGenerator.Application/Services/EnvelopeTypeService.cs b/EnvelopeGenerator.Application/Services/EnvelopeTypeService.cs index dd944892..c43a0cb8 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeTypeService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeTypeService.cs @@ -5,6 +5,7 @@ using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.DTOs; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; +using EnvelopeGenerator.Application.Resources; namespace EnvelopeGenerator.Application.Services { diff --git a/EnvelopeGenerator.Application/Services/ReceiverService.cs b/EnvelopeGenerator.Application/Services/ReceiverService.cs index e0f375a7..9fc76b95 100644 --- a/EnvelopeGenerator.Application/Services/ReceiverService.cs +++ b/EnvelopeGenerator.Application/Services/ReceiverService.cs @@ -5,6 +5,7 @@ using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.DTOs; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; +using EnvelopeGenerator.Application.Resources; namespace EnvelopeGenerator.Application.Services { diff --git a/EnvelopeGenerator.Application/Services/UserReceiverService.cs b/EnvelopeGenerator.Application/Services/UserReceiverService.cs index 30d7d38d..9fe3ee72 100644 --- a/EnvelopeGenerator.Application/Services/UserReceiverService.cs +++ b/EnvelopeGenerator.Application/Services/UserReceiverService.cs @@ -5,6 +5,7 @@ using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.DTOs; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Infrastructure.Contracts; +using EnvelopeGenerator.Application.Resources; namespace EnvelopeGenerator.Application.Services { diff --git a/EnvelopeGenerator.Web/Controllers/HomeController.cs b/EnvelopeGenerator.Web/Controllers/HomeController.cs index 5c5a19eb..52fbab73 100644 --- a/EnvelopeGenerator.Web/Controllers/HomeController.cs +++ b/EnvelopeGenerator.Web/Controllers/HomeController.cs @@ -15,6 +15,7 @@ using EnvelopeGenerator.Application.DTOs; using Microsoft.AspNetCore.Localization; using System.Text.Encodings.Web; using EnvelopeGenerator.Web.Models; +using EnvelopeGenerator.Application.Resources; namespace EnvelopeGenerator.Web.Controllers { @@ -76,11 +77,24 @@ namespace EnvelopeGenerator.Web.Controllers } [HttpGet("EnvelopeKey/{envelopeReceiverId}/Locked")] - public async Task EnvelopeLocked([FromRoute] string envelopeReceiverId) + public async Task EnvelopeLocked([FromRoute] string envelopeReceiverId, [FromQuery] string? culture) { try { + culture = culture is not null ? _urlEncoder.Encode(culture) : null; envelopeReceiverId = _urlEncoder.Encode(envelopeReceiverId); + + if (UserLanguage is null && culture is null) + { + UserLanguage = _cultures.Default.Language; + return Redirect($"{Request.Headers["Referer"]}?culture={_cultures.Default.Language}"); + } + + if (UserLanguage is not null && culture is not null) + { + return Redirect($"Locked"); + } + ViewData["UserLanguage"] = UserLanguage; return await _envRcvService.IsExisting(envelopeReceiverId: envelopeReceiverId).ThenAsync( @@ -250,32 +264,37 @@ namespace EnvelopeGenerator.Web.Controllers [HttpGet("lang")] public IActionResult GetLanguages() => Ok(_cultures.Languages); - private string UserLanguage + private string? UserLanguage { get { var cookieValue = Request.Cookies[CookieRequestCultureProvider.DefaultCookieName]; if (string.IsNullOrEmpty(cookieValue)) - return _cultures.Default.Language; + return null; var culture = CookieRequestCultureProvider.ParseCookieValue(cookieValue)?.Cultures[0]; - return culture?.Value ?? _cultures.Default.Language; + return culture?.Value ?? null; } set { - var cookieOptions = new CookieOptions() + if(value is null) + Response.Cookies.Delete(CookieRequestCultureProvider.DefaultCookieName); + else { - Expires = DateTimeOffset.UtcNow.AddYears(1), - Secure = false, - SameSite = SameSiteMode.Strict, - HttpOnly = true - }; + var cookieOptions = new CookieOptions() + { + Expires = DateTimeOffset.UtcNow.AddYears(1), + Secure = false, + SameSite = SameSiteMode.Strict, + HttpOnly = true + }; - Response.Cookies.Append( - CookieRequestCultureProvider.DefaultCookieName, - CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(value)), - cookieOptions); + Response.Cookies.Append( + CookieRequestCultureProvider.DefaultCookieName, + CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(value)), + cookieOptions); + } } } diff --git a/EnvelopeGenerator.Web/Controllers/Test/TestLocalizerController.cs b/EnvelopeGenerator.Web/Controllers/Test/TestLocalizerController.cs index fec38a90..31c641a6 100644 --- a/EnvelopeGenerator.Web/Controllers/Test/TestLocalizerController.cs +++ b/EnvelopeGenerator.Web/Controllers/Test/TestLocalizerController.cs @@ -1,5 +1,5 @@ using AngleSharp.Common; -using EnvelopeGenerator.Application; +using EnvelopeGenerator.Application.Resources; using EnvelopeGenerator.Web.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; diff --git a/EnvelopeGenerator.Web/Program.cs b/EnvelopeGenerator.Web/Program.cs index 994bdcb4..856189a8 100644 --- a/EnvelopeGenerator.Web/Program.cs +++ b/EnvelopeGenerator.Web/Program.cs @@ -71,8 +71,7 @@ try //AddEF Core dbcontext var connStr = config["Config:ConnectionString"]; - builder.Services.AddDbContext(options => - options.UseSqlServer(connStr)); + builder.Services.AddDbContext(options => options.UseSqlServer(connStr)); //Inject CRUD Service and repositoriesad builder.Services.AddScoped(); @@ -156,7 +155,7 @@ try builder.Services.AddCookieConsentSettings(); - builder.Services.AddCookieBasedLocalizer("Resources"); + builder.Services.AddCookieBasedLocalizer(); builder.Services.AddSingleton(HtmlEncoder.Default); builder.Services.AddSingleton(UrlEncoder.Default); @@ -207,7 +206,7 @@ try app.UseAuthorization(); var cultures = app.Services.GetRequiredService(); - if(cultures.Any()) + if(!cultures.Any()) throw new InvalidOperationException(@"Languages section is missing in the appsettings. Please configure like following. Language is both a name of the culture and the name of the resx file such as Resource.de-DE.resx FIClass is the css class (in wwwroot/lib/flag-icons-main) for the flag of country. diff --git a/EnvelopeGenerator.Web/Views/_ViewImports.cshtml b/EnvelopeGenerator.Web/Views/_ViewImports.cshtml index 67a39c0c..7d1c9b1d 100644 --- a/EnvelopeGenerator.Web/Views/_ViewImports.cshtml +++ b/EnvelopeGenerator.Web/Views/_ViewImports.cshtml @@ -1,7 +1,7 @@ @using EnvelopeGenerator.Web @using EnvelopeGenerator.Web.Models @using Microsoft.Extensions.Localization -@using EnvelopeGenerator.Application +@using EnvelopeGenerator.Application.Resources @inject IStringLocalizer _localizer @inject System.Text.Encodings.Web.UrlEncoder _encoder @inject Ganss.Xss.HtmlSanitizer _sanitizer