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)
{
@ChildContent
}
else
{
@((MarkupString)Convert.ToString(Localizer["ConsentBody"]))
}
<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)
{
<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

@ -22,7 +22,7 @@
</div>
</div>
</div>
<Pane Name="Top Full Width" />
<Pane Name="Top Full Width" />
<div class="container">
<div class="row">
<div class="col-md-12">
@ -107,18 +107,19 @@
{
<Pane Name="Footer" />
}
<CookieConsent />
</div>
<CookieConsent Enabled="@_displayCookieConsent" />
</div>
</main>
@code {
public override string Name => "Default Theme";
public override string Panes => PaneNames.Default + ",Top Full Width,Top 100%,Left 50%,Right 50%,Left 33%,Center 33%,Right 33%,Left Outer 25%,Left Inner 25%,Right Inner 25%,Right Outer 25%,Left 25%,Center 50%,Right 25%,Left Sidebar 66%,Right Sidebar 33%,Left Sidebar 33%,Right Sidebar 66%,Bottom 100%,Bottom Full Width,Footer";
public override string Panes => PaneNames.Default + ",Top Full Width,Top 100%,Left 50%,Right 50%,Left 33%,Center 33%,Right 33%,Left Outer 25%,Left Inner 25%,Right Inner 25%,Right Outer 25%,Left 25%,Center 50%,Right 25%,Left Sidebar 66%,Right Sidebar 33%,Left Sidebar 33%,Right Sidebar 66%,Bottom 100%,Bottom Full Width,Footer";
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

@ -13,9 +13,9 @@
<select id="scope" class="form-select" value="@_scope" @onchange="(e => ScopeChanged(e))">
@if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Admin))
{
<option value="site">@Localizer["Site"]</option>
<option value="site">@Localizer["Site"]</option>
}
<option value="page">@Localizer["Page"]</option>
<option value="page">@Localizer["Page"]</option>
</select>
</div>
</div>
@ -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
{
@ -92,7 +104,8 @@
settings = SettingService.MergeSettings(PageState.Site.Settings, settings);
_login = SettingService.GetSetting(settings, GetType().Namespace + ":Login", "-");
_register = SettingService.GetSetting(settings, GetType().Namespace + ":Register", "-");
_footer = SettingService.GetSetting(settings, GetType().Namespace + ":Footer", "-");
_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";