update the cookie consent control.

This commit is contained in:
Ben 2025-02-25 11:36:47 +08:00
parent bf308dd13d
commit b47bf40e8f
9 changed files with 134 additions and 32 deletions

View File

@ -117,16 +117,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ConsentBody" xml:space="preserve">
<value>
&lt;div class="gdpr-consent-bar bg-light text-dark p-3 fixed-bottom"&gt;
&lt;div class="container-fluid d-flex justify-content-between align-items-center"&gt;
&lt;div&gt;
By clicking "Accept", you agree us to use cookies to ensure you get the best experience on our website.
&lt;/div&gt;
&lt;button class="btn btn-primary" type="submit"&gt;Accept&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
</value>
<data name="Apply" xml:space="preserve">
<value>Apply</value>
</data>
<data name="ConsentDescription" xml:space="preserve">
<value>By clicking "Accept", you agree us to use cookies to ensure you get the best experience on our website.</value>
</data>
<data name="Privacy" xml:space="preserve">
<value>Privacy</value>
</data>
</root>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
@ -147,4 +147,10 @@
<data name="Site" xml:space="preserve">
<value>Site</value>
</data>
<data name="DisplayCookieConsent.HelpText" xml:space="preserve">
<value>Specify whether display the cookie consent bar.</value>
</data>
<data name="DisplayCookieConsent.Text" xml:space="preserve">
<value>Display Cookie Consent?</value>
</data>
</root>

View File

@ -26,7 +26,7 @@
<div class="container">
<div class="row px-4">
<Pane Name="@PaneNames.Admin" />
<CookieConsent />
<CookieConsent Enabled="true" />
</div>
</div>
</div>

View File

@ -4,25 +4,35 @@
@inject IJSRuntime JSRuntime
@inject IStringLocalizer<CookieConsent> Localizer
@if (showBanner)
@if (Enabled && showBanner)
{
<form method="post" @formname="CookieConsentForm" @onsubmit="async () => await AcceptPolicy()" data-enhance>
<input type="hidden" name="@Constants.RequestVerificationToken" value="@SiteState.AntiForgeryToken" />
@if (ChildContent != null)
<div class="gdpr-consent-bar bg-light text-dark p-3 fixed-bottom">
<div class="container-fluid d-flex justify-content-between align-items-center">
<div>
@((MarkupString)Convert.ToString(Localizer["ConsentDescription"]))
</div>
<div>
<button class="btn btn-primary" type="submit">@((MarkupString)Convert.ToString(Localizer["Apply"]))</button>
@if (ShowPrivacyLink)
{
@ChildContent
}
else
{
@((MarkupString)Convert.ToString(Localizer["ConsentBody"]))
<a class="btn btn-secondary ms-2" href="/privacy" target="_blank">@((MarkupString)Convert.ToString(Localizer["Privacy"]))</a>
}
</div>
</div>
</div>
</form>
}
@code {
private bool showBanner;
[Parameter]
public RenderFragment ChildContent { get; set; } = null;
public bool Enabled { get; set; }
[Parameter]
public bool ShowPrivacyLink { get; set; } = true;
protected override async Task OnInitializedAsync()
{

View File

@ -107,7 +107,7 @@
{
<Pane Name="Footer" />
}
<CookieConsent />
<CookieConsent Enabled="@_displayCookieConsent" />
</div>
</main>
@ -119,6 +119,7 @@
private bool _login = true;
private bool _register = true;
private bool _footer = false;
private bool _displayCookieConsent = false;
protected override void OnParametersSet()
{
@ -128,6 +129,7 @@
_login = bool.Parse(SettingService.GetSetting(settings, GetType().Namespace + ":Login", "true"));
_register = bool.Parse(SettingService.GetSetting(settings, GetType().Namespace + ":Register", "true"));
_footer = bool.Parse(SettingService.GetSetting(settings, GetType().Namespace + ":Footer", "false"));
_displayCookieConsent = bool.Parse(SettingService.GetSetting(settings, GetType().Namespace + ":DisplayCookieConsent", "false"));
}
catch
{

View File

@ -49,6 +49,16 @@
</select>
</div>
</div>
<div class="row mb-1 align-items-center">
<Label Class="col-sm-3" For="displayCookieConsent" ResourceKey="DisplayCookieConsent" ResourceType="@resourceType" HelpText="Specify whether display the cookie consent bar.">Display Cookie Consent?</Label>
<div class="col-sm-9">
<select id="footer" class="form-select" @bind="@_displayCookieConsent">
<option value="-">&lt;@SharedLocalizer["Not Specified"]&gt;</option>
<option value="true">@SharedLocalizer["Yes"]</option>
<option value="false">@SharedLocalizer["No"]</option>
</select>
</div>
</div>
</div>
@code {
@ -58,6 +68,7 @@
private string _login = "-";
private string _register = "-";
private string _footer = "-";
private string _displayCookieConsent = "-";
protected override async Task OnInitializedAsync()
{
@ -85,6 +96,7 @@
_login = SettingService.GetSetting(settings, GetType().Namespace + ":Login", "true");
_register = SettingService.GetSetting(settings, GetType().Namespace + ":Register", "true");
_footer = SettingService.GetSetting(settings, GetType().Namespace + ":Footer", "false");
_displayCookieConsent = SettingService.GetSetting(settings, GetType().Namespace + ":DisplayCookieConsent", "false");
}
else
{
@ -93,6 +105,7 @@
_login = SettingService.GetSetting(settings, GetType().Namespace + ":Login", "-");
_register = SettingService.GetSetting(settings, GetType().Namespace + ":Register", "-");
_footer = SettingService.GetSetting(settings, GetType().Namespace + ":Footer", "-");
_displayCookieConsent = SettingService.GetSetting(settings, GetType().Namespace + ":DisplayCookieConsent", "-");
}
await Task.Yield();
}
@ -131,6 +144,11 @@
{
settings = SettingService.SetSetting(settings, GetType().Namespace + ":Footer", _footer);
}
if (_displayCookieConsent != "-")
{
settings = SettingService.SetSetting(settings, GetType().Namespace + ":DisplayCookieConsent", _displayCookieConsent);
}
await SettingService.UpdateSiteSettingsAsync(settings, PageState.Site.SiteId);
}
else
@ -148,6 +166,10 @@
{
settings = SettingService.SetSetting(settings, GetType().Namespace + ":Footer", _footer);
}
if (_displayCookieConsent != "-")
{
settings = SettingService.SetSetting(settings, GetType().Namespace + ":DisplayCookieConsent", _displayCookieConsent);
}
await SettingService.UpdatePageSettingsAsync(settings, pageId);
}
}

View File

@ -169,6 +169,33 @@ namespace Oqtane.SiteTemplates
}
});
pageTemplates.Add(new PageTemplate
{
Name = "Privacy",
Parent = "",
Path = "privacy",
Icon = Icons.Eye,
IsNavigation = false,
IsPersonalizable = false,
PermissionList = new List<Permission>
{
new Permission(PermissionNames.View, RoleNames.Everyone, true),
new Permission(PermissionNames.View, RoleNames.Admin, true),
new Permission(PermissionNames.Edit, RoleNames.Admin, true)
},
PageTemplateModules = new List<PageTemplateModule>
{
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.HtmlText, Oqtane.Client", Title = "Privacy Policy", Pane = PaneNames.Default,
PermissionList = new List<Permission> {
new Permission(PermissionNames.View, RoleNames.Everyone, true),
new Permission(PermissionNames.View, RoleNames.Admin, true),
new Permission(PermissionNames.Edit, RoleNames.Admin, true)
},
Content = "<p>By using our website, you agree to this privacy policy. We value your privacy and are committed to protecting your personal information. This policy outlines how we collect, use, and safeguard your data when you visit our website or use our services.</p>"
}
}
});
pageTemplates.Add(new PageTemplate
{
Name = "Not Found",

View File

@ -75,6 +75,9 @@ namespace Oqtane.Infrastructure
case "6.1.0":
Upgrade_6_1_0(tenant, scope);
break;
case "6.1.1":
Upgrade_6_1_1(tenant, scope);
break;
}
}
}
@ -457,6 +460,41 @@ namespace Oqtane.Infrastructure
RemoveAssemblies(tenant, assemblies, "6.1.0");
}
private void Upgrade_6_1_1(Tenant tenant, IServiceScope scope)
{
var pageTemplates = new List<PageTemplate>
{
new PageTemplate
{
Name = "Privacy",
Parent = "",
Path = "privacy",
Icon = Icons.Eye,
IsNavigation = false,
IsPersonalizable = false,
PermissionList = new List<Permission>
{
new Permission(PermissionNames.View, RoleNames.Everyone, true),
new Permission(PermissionNames.View, RoleNames.Admin, true),
new Permission(PermissionNames.Edit, RoleNames.Admin, true)
},
PageTemplateModules = new List<PageTemplateModule>
{
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.HtmlText, Oqtane.Client", Title = "Privacy Policy", Pane = PaneNames.Default,
PermissionList = new List<Permission> {
new Permission(PermissionNames.View, RoleNames.Everyone, true),
new Permission(PermissionNames.View, RoleNames.Admin, true),
new Permission(PermissionNames.Edit, RoleNames.Admin, true)
},
Content = "<p>By using our website, you agree to this privacy policy. We value your privacy and are committed to protecting your personal information. This policy outlines how we collect, use, and safeguard your data when you visit our website or use our services.</p>"
}
}
}
};
AddPagesToSites(scope, tenant, pageTemplates);
}
private void AddPagesToSites(IServiceScope scope, Tenant tenant, List<PageTemplate> pageTemplates)
{
var tenants = scope.ServiceProvider.GetRequiredService<ITenantManager>();

View File

@ -4,8 +4,8 @@ namespace Oqtane.Shared
{
public class Constants
{
public static readonly string Version = "6.1.0";
public const string ReleaseVersions = "1.0.0,1.0.1,1.0.2,1.0.3,1.0.4,2.0.0,2.0.1,2.0.2,2.1.0,2.2.0,2.3.0,2.3.1,3.0.0,3.0.1,3.0.2,3.0.3,3.1.0,3.1.1,3.1.2,3.1.3,3.1.4,3.2.0,3.2.1,3.3.0,3.3.1,3.4.0,3.4.1,3.4.2,3.4.3,4.0.0,4.0.1,4.0.2,4.0.3,4.0.4,4.0.5,4.0.6,5.0.0,5.0.1,5.0.2,5.0.3,5.1.0,5.1.1,5.1.2,5.2.0,5.2.1,5.2.2,5.2.3,5.2.4,6.0.0,6.0.1,6.1.0";
public static readonly string Version = "6.1.1";
public const string ReleaseVersions = "1.0.0,1.0.1,1.0.2,1.0.3,1.0.4,2.0.0,2.0.1,2.0.2,2.1.0,2.2.0,2.3.0,2.3.1,3.0.0,3.0.1,3.0.2,3.0.3,3.1.0,3.1.1,3.1.2,3.1.3,3.1.4,3.2.0,3.2.1,3.3.0,3.3.1,3.4.0,3.4.1,3.4.2,3.4.3,4.0.0,4.0.1,4.0.2,4.0.3,4.0.4,4.0.5,4.0.6,5.0.0,5.0.1,5.0.2,5.0.3,5.1.0,5.1.1,5.1.2,5.2.0,5.2.1,5.2.2,5.2.3,5.2.4,6.0.0,6.0.1,6.1.0,6.1.1";
public const string PackageId = "Oqtane.Framework";
public const string ClientId = "Oqtane.Client";
public const string UpdaterPackageId = "Oqtane.Updater";