diff --git a/Moonlight/Core/Configuration/CoreConfiguration.cs b/Moonlight/Core/Configuration/CoreConfiguration.cs index 6af7336c..ee06a257 100644 --- a/Moonlight/Core/Configuration/CoreConfiguration.cs +++ b/Moonlight/Core/Configuration/CoreConfiguration.cs @@ -116,6 +116,7 @@ public class CoreConfiguration public FileManagerData FileManager { get; set; } = new(); [JsonProperty("Footer")] public FooterData Footer { get; set; } = new(); + [JsonProperty("CookieConsentBanner")] public CookieData CookieConsentBanner{ get; set; } = new(); } public class FooterData @@ -147,4 +148,27 @@ public class CoreConfiguration [Description("This specifies the general timeout for file manager operations. This can but has not to be used by file accesses")] public int OperationTimeout { get; set; } = 5; } + + public class CookieData + { + [JsonProperty("ShowCookieConsentBanner")] + [Description("This specifies if the cookie consent banner is shown to users.")] + public bool ShowBanner { get; set; } = true; + + [JsonProperty("BannerTitle")] + [Description("The title for the cookie consent banner.")] + public string BannerTitle = "\ud83c\udf6a Cookies"; + + [JsonProperty("BannerText")] + [Description("The description for the cookie consent banner.")] + public string BannerText = "Moonlight is using cookies \ud83c\udf6a, to personalize your experience."; + + [JsonProperty("ConsentText")] + [Description("The text for the consent option.")] + public string ConsentText = "Consent"; + + [JsonProperty("DeclineText")] + [Description("The text for the decline option.")] + public string DeclineText = "Decline"; + } } \ No newline at end of file diff --git a/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor b/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor new file mode 100644 index 00000000..863d3608 --- /dev/null +++ b/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor @@ -0,0 +1,60 @@ +@using ApexCharts +@using MoonCore.Services +@using Moonlight.Core.Configuration +@using Moonlight.Core.Services + +@inject ConfigService ConfigService +@inject IdentityService IdentityService + +@ChildContent + +@if (ConfigService.Get().Customisation.CookieConsentBanner.ShowBanner && !IdentityService.HasFlag("CookieAsked").Result) +{ +
+
+
+
+

@ConfigService.Get().Customisation.CookieConsentBanner.BannerTitle

+

+ @ConfigService.Get().Customisation.CookieConsentBanner.BannerText +

+ + + @ConfigService.Get().Customisation.CookieConsentBanner.ConsentText + + + @ConfigService.Get().Customisation.CookieConsentBanner.DeclineText + + +
+
+
+
+} +@code { + + [Parameter] + public RenderFragment ChildContent { get; set; } + + private async Task Consent() + { + if (!IdentityService.IsLoggedIn) + return; + + await IdentityService.SetFlag("CookieAsked", true); + await IdentityService.SetFlag("CookieConsent", true); + + await InvokeAsync(StateHasChanged); + } + + private async Task Decline() + { + if (!IdentityService.IsLoggedIn) + return; + + await IdentityService.SetFlag("CookieAsked", true); + + await InvokeAsync(StateHasChanged); + } + +} \ No newline at end of file diff --git a/Moonlight/Core/UI/Layouts/MainLayout.razor b/Moonlight/Core/UI/Layouts/MainLayout.razor index 964cc2ec..f5884ab6 100644 --- a/Moonlight/Core/UI/Layouts/MainLayout.razor +++ b/Moonlight/Core/UI/Layouts/MainLayout.razor @@ -55,7 +55,9 @@ if (IdentityService.IsLoggedIn) { - @Body + + @Body + } else