From 0fd60b5ccbc060e8ee91aacc1b02c792665f22c5 Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Sat, 8 Jun 2024 11:45:39 +0200 Subject: [PATCH 1/6] Added the cookie consent banner --- .../Core/Configuration/CoreConfiguration.cs | 24 ++++++++ .../Partials/CookieConsentBanner.razor | 60 +++++++++++++++++++ Moonlight/Core/UI/Layouts/MainLayout.razor | 4 +- 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor 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 From 87f93b3caba040a6c555df985ab089f20b67ca1c Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Sat, 8 Jun 2024 12:02:00 +0200 Subject: [PATCH 2/6] Added Cookie Settings option on the account settings --- .../Core/Models/Forms/ChangeCookiesForm.cs | 9 +++++ .../Core/UI/Views/Account/Security.razor | 33 ++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 Moonlight/Core/Models/Forms/ChangeCookiesForm.cs diff --git a/Moonlight/Core/Models/Forms/ChangeCookiesForm.cs b/Moonlight/Core/Models/Forms/ChangeCookiesForm.cs new file mode 100644 index 00000000..0090240e --- /dev/null +++ b/Moonlight/Core/Models/Forms/ChangeCookiesForm.cs @@ -0,0 +1,9 @@ +using System.ComponentModel; + +namespace Moonlight.Core.Models.Forms; + +public class ChangeCookiesForm +{ + [Description("This specifies if you would like to personalize your experience with optional cookies.")] + public bool UseOptionalCookies { get; set; } = false; +} \ No newline at end of file diff --git a/Moonlight/Core/UI/Views/Account/Security.razor b/Moonlight/Core/UI/Views/Account/Security.razor index eb69af0a..7c2cb050 100644 --- a/Moonlight/Core/UI/Views/Account/Security.razor +++ b/Moonlight/Core/UI/Views/Account/Security.razor @@ -28,7 +28,7 @@
- +
@@ -47,19 +47,37 @@
+
+
+ +
+

Cookies

+
+ + +
+
+ +
+
+
@code { private readonly ChangePasswordForm PasswordForm = new(); + + private ChangeCookiesForm CookiesForm = new(); - private Task Load(LazyLoader lazyLoader) + private async Task Load(LazyLoader lazyLoader) { - return Task.CompletedTask; + CookiesForm.UseOptionalCookies = await IdentityService.HasFlag("CookieConsent"); } - private async Task OnValidSubmit() + private async Task OnValidSubmitPassword() { if (PasswordForm.Password != PasswordForm.RepeatedPassword) throw new DisplayException("The passwords do not match"); @@ -69,4 +87,11 @@ await ToastService.Success("Successfully changed password"); await IdentityService.Authenticate(true); } + + private async Task OnValidSubmitCookie() + { + await IdentityService.SetFlag("CookieConsent", CookiesForm.UseOptionalCookies); + + await InvokeAsync(StateHasChanged); + } } \ No newline at end of file From 8b489da287046f08dcb3d454f6b5a17e07fa6881 Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Sat, 8 Jun 2024 12:08:48 +0200 Subject: [PATCH 3/6] Updated the styling for the cookieconsent banner --- .../Core/UI/Components/Partials/CookieConsentBanner.razor | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor b/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor index 863d3608..8d79b088 100644 --- a/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor +++ b/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor @@ -12,17 +12,17 @@ {
-
+

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

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

- + @ConfigService.Get().Customisation.CookieConsentBanner.ConsentText - + @ConfigService.Get().Customisation.CookieConsentBanner.DeclineText From a0f256946e2e2b01991d5b5758dbb19cbbcf1301 Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Sat, 8 Jun 2024 12:16:56 +0200 Subject: [PATCH 4/6] I forgot the {get; set;} --- Moonlight/Core/Configuration/CoreConfiguration.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Moonlight/Core/Configuration/CoreConfiguration.cs b/Moonlight/Core/Configuration/CoreConfiguration.cs index ee06a257..3dc24700 100644 --- a/Moonlight/Core/Configuration/CoreConfiguration.cs +++ b/Moonlight/Core/Configuration/CoreConfiguration.cs @@ -157,18 +157,18 @@ public class CoreConfiguration [JsonProperty("BannerTitle")] [Description("The title for the cookie consent banner.")] - public string BannerTitle = "\ud83c\udf6a Cookies"; + public string BannerTitle { get; set; } = "\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."; + public string BannerText { get; set; } = "Moonlight is using cookies \ud83c\udf6a, to personalize your experience."; [JsonProperty("ConsentText")] [Description("The text for the consent option.")] - public string ConsentText = "Consent"; + public string ConsentText { get; set; } = "Consent"; [JsonProperty("DeclineText")] [Description("The text for the decline option.")] - public string DeclineText = "Decline"; + public string DeclineText { get; set; } = "Decline"; } } \ No newline at end of file From 862b43ae6d0d01bf5dd397c048c7e7fbeacd28c0 Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Sun, 9 Jun 2024 10:33:04 +0200 Subject: [PATCH 5/6] Fixed some dump mistakes --- .../Core/Configuration/CoreConfiguration.cs | 4 ++-- .../Partials/CookieConsentBanner.razor | 21 ++++++++++++++----- Moonlight/Core/UI/Layouts/MainLayout.razor | 5 ++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Moonlight/Core/Configuration/CoreConfiguration.cs b/Moonlight/Core/Configuration/CoreConfiguration.cs index 3dc24700..c972e95e 100644 --- a/Moonlight/Core/Configuration/CoreConfiguration.cs +++ b/Moonlight/Core/Configuration/CoreConfiguration.cs @@ -151,9 +151,9 @@ public class CoreConfiguration public class CookieData { - [JsonProperty("ShowCookieConsentBanner")] + [JsonProperty("Enabled")] [Description("This specifies if the cookie consent banner is shown to users.")] - public bool ShowBanner { get; set; } = true; + public bool Enabled { get; set; } = true; [JsonProperty("BannerTitle")] [Description("The title for the cookie consent banner.")] diff --git a/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor b/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor index 8d79b088..f6b4b00e 100644 --- a/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor +++ b/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor @@ -6,9 +6,7 @@ @inject ConfigService ConfigService @inject IdentityService IdentityService -@ChildContent - -@if (ConfigService.Get().Customisation.CookieConsentBanner.ShowBanner && !IdentityService.HasFlag("CookieAsked").Result) +@if (ShowBanner) {
@@ -31,10 +29,23 @@
} + @code { - [Parameter] - public RenderFragment ChildContent { get; set; } + private bool ShowBanner; + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + var userWasAsked = await IdentityService.HasFlag("CookieAsked"); + + if (ConfigService.Get().Customisation.CookieConsentBanner.Enabled && !userWasAsked) + ShowBanner = true; + + await InvokeAsync(StateHasChanged); + } + } private async Task Consent() { diff --git a/Moonlight/Core/UI/Layouts/MainLayout.razor b/Moonlight/Core/UI/Layouts/MainLayout.razor index f5884ab6..f0007150 100644 --- a/Moonlight/Core/UI/Layouts/MainLayout.razor +++ b/Moonlight/Core/UI/Layouts/MainLayout.razor @@ -55,9 +55,8 @@ if (IdentityService.IsLoggedIn) { - - @Body - + @Body + } else From 38b93cd5004de084fe3091f8b1dd85ec3c688ef4 Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Thu, 13 Jun 2024 17:39:02 +0200 Subject: [PATCH 6/6] Cookie consent is disabled by default --- Moonlight/Core/Configuration/CoreConfiguration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moonlight/Core/Configuration/CoreConfiguration.cs b/Moonlight/Core/Configuration/CoreConfiguration.cs index c972e95e..38930921 100644 --- a/Moonlight/Core/Configuration/CoreConfiguration.cs +++ b/Moonlight/Core/Configuration/CoreConfiguration.cs @@ -153,7 +153,7 @@ public class CoreConfiguration { [JsonProperty("Enabled")] [Description("This specifies if the cookie consent banner is shown to users.")] - public bool Enabled { get; set; } = true; + public bool Enabled { get; set; } = false; [JsonProperty("BannerTitle")] [Description("The title for the cookie consent banner.")]