Fix #4936: add the cookie consent theme control.
This commit is contained in:
@ -26,9 +26,11 @@
|
||||
<div class="container">
|
||||
<div class="row px-4">
|
||||
<Pane Name="@PaneNames.Admin" />
|
||||
<CookieConsent />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
33
Oqtane.Client/Themes/Controls/Theme/CookieConsent.razor
Normal file
33
Oqtane.Client/Themes/Controls/Theme/CookieConsent.razor
Normal file
@ -0,0 +1,33 @@
|
||||
@namespace Oqtane.Themes.Controls
|
||||
@inherits ThemeControlBase
|
||||
@inject ICookieConsentService CookieConsentService
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject IStringLocalizer<CookieConsent> Localizer
|
||||
|
||||
@if (showBanner)
|
||||
{
|
||||
<form method="post" @formname="CookieConsentForm" @onsubmit="async () => await AcceptPolicy()" data-enhance>
|
||||
<input type="hidden" name="@Constants.RequestVerificationToken" value="@SiteState.AntiForgeryToken" />
|
||||
@((MarkupString)Convert.ToString(Localizer["ConsentBody"]))
|
||||
</form>
|
||||
}
|
||||
@code {
|
||||
private bool showBanner;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
showBanner = !(await CookieConsentService.CanTrackAsync());
|
||||
}
|
||||
|
||||
private async Task AcceptPolicy()
|
||||
{
|
||||
var cookieString = await CookieConsentService.CreateConsentCookieAsync();
|
||||
if (!string.IsNullOrEmpty(cookieString))
|
||||
{
|
||||
var interop = new Interop(JSRuntime);
|
||||
await interop.SetCookieString(cookieString);
|
||||
|
||||
showBanner = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -107,6 +107,7 @@
|
||||
{
|
||||
<Pane Name="Footer" />
|
||||
}
|
||||
<CookieConsent />
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
Reference in New Issue
Block a user