Skip to content

Commit

Permalink
Merge pull request #453 from poppastring/gdpr-support
Browse files Browse the repository at this point in the history
Gdpr support

close #358
  • Loading branch information
poppastring authored Aug 30, 2020
2 parents 39852ba + a316484 commit 1aff31d
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 14 deletions.
2 changes: 1 addition & 1 deletion source/DasBlog All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DasBlog.Services", "DasBlog
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DasBlog.Test.Integration", "DasBlog.Tests\DasBlog.Test.Integration\DasBlog.Test.Integration.csproj", "{48500D1A-9780-412B-81C1-9DD810FECCAE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DasBlog.CLI", "DasBlog.CLI\DasBlog.CLI.csproj", "{3DEF6C9E-293A-4E41-9CEC-3466E3EEC754}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DasBlog.CLI", "DasBlog.CLI\DasBlog.CLI.csproj", "{3DEF6C9E-293A-4E41-9CEC-3466E3EEC754}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
4 changes: 3 additions & 1 deletion source/DasBlog.Services/ConfigFile/Interfaces/ISiteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ public interface ISiteConfig

bool UseAspxExtension { get; set; }

[XmlAnyElement]
bool CookieConsentEnabled { get; set; }

[XmlAnyElement]
XmlElement[] anyElements { get; set; }

[XmlAnyAttribute]
Expand Down
1 change: 1 addition & 0 deletions source/DasBlog.Services/ConfigFile/SiteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,6 @@ public SiteConfig() { }
public ValidCommentTags [] ValidCommentTags { get; set; }

public bool UseAspxExtension { get; set; }
public bool CookieConsentEnabled { get; set; }
}
}
1 change: 1 addition & 0 deletions source/DasBlog.Tests/UnitTests/SiteConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public class SiteConfigTest : ISiteConfig
public XmlAttribute[] anyAttributes { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool ShowItemSummaryInAggregatedViews { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool UseAspxExtension { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool CookieConsentEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
ValidCommentTags[] ISiteConfig.ValidCommentTags { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
}
}
4 changes: 2 additions & 2 deletions source/DasBlog.Web.UI/Config/site.Development.config
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@

<EnableBloggerApi>true</EnableBloggerApi>



<EnableDailyReportEmail>false</EnableDailyReportEmail>
<SendCommentsByEmail>false</SendCommentsByEmail>

Expand All @@ -110,6 +108,8 @@
<UseSSLForSMTP>false</UseSSLForSMTP>
<EnableSmtpAuthentication>true</EnableSmtpAuthentication>

<CookieConsentEnabled>false</CookieConsentEnabled>

<!-- Settings below this line are not currently in use -->
<!-- _________________________________________________ -->
<CommentsAllowHtml>true</CommentsAllowHtml>
Expand Down
2 changes: 2 additions & 0 deletions source/DasBlog.Web.UI/Config/site.config
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
<UseSSLForSMTP>false</UseSSLForSMTP>
<EnableSmtpAuthentication>true</EnableSmtpAuthentication>

<CookieConsentEnabled>false</CookieConsentEnabled>

<!-- Settings below this line are not currently in use -->
<!-- _________________________________________________ -->
<CommentsAllowHtml>true</CommentsAllowHtml>
Expand Down
3 changes: 3 additions & 0 deletions source/DasBlog.Web.UI/Models/AdminViewModels/SiteViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ public class SiteViewModel
[Description("")]
public bool UseAspxExtension { get; set; }

[DisplayName("Cookie Consent (GDPR Support)")]
[Description("Help meet some of the EU General Data Protection Regulation (GDPR) requirements")]
public bool CookieConsentEnabled { get; set; }

public bool EntryTitleAsLink { get; set; }
public bool ObfuscateEmail { get; set; }
Expand Down
27 changes: 18 additions & 9 deletions source/DasBlog.Web.UI/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
using DasBlog.Managers.Interfaces;
using DasBlog.Services.ActivityLogs;
using DasBlog.Services.ConfigFile.Interfaces;
using DasBlog.Services;
using DasBlog.Services.ConfigFile;
using DasBlog.Services.FileManagement;
using DasBlog.Services.FileManagement.Interfaces;
using DasBlog.Services.Scheduler;
using DasBlog.Services.Site;
using DasBlog.Services.Users;
using DasBlog.Web.Identity;
using DasBlog.Web.Settings;
using DasBlog.Web.Mappers;
Expand All @@ -14,28 +20,22 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Rewrite;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Quartz;
using System;
using System.IO;
using System.Linq;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using DasBlog.Services.Site;
using DasBlog.Services.ConfigFile;
using DasBlog.Services.Users;
using DasBlog.Services;
using Microsoft.AspNetCore.HttpOverrides;
using DasBlog.Services.FileManagement.Interfaces;
using Microsoft.Extensions.Logging;
using Quartz;
using DasBlog.Services.Scheduler;

namespace DasBlog.Web
{
Expand Down Expand Up @@ -226,6 +226,14 @@ public void ConfigureServices(IServiceCollection services)
.AddControllersWithViews()
.AddRazorRuntimeCompilation();

services.Configure<CookiePolicyOptions>(options =>
{
bool.TryParse(Configuration.GetSection("CookieConsentEnabled").Value, out var flag);
options.CheckConsentNeeded = context => flag;
options.MinimumSameSitePolicy = SameSiteMode.None;
});

services.AddQuartz(q =>
{
q.SchedulerId = "Scheduler-Core";
Expand Down Expand Up @@ -311,6 +319,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IDasBlog
app.UseForwardedHeaders();

app.UseStaticFiles();
app.UseCookiePolicy();

app.UseStaticFiles(new StaticFileOptions()
{
Expand Down
2 changes: 2 additions & 0 deletions source/DasBlog.Web.UI/Themes/darkly/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

<div class="container body-content">

<partial name="_CookieConsentPartial" />

@RenderBody()

<div class="container text-center">
Expand Down
2 changes: 1 addition & 1 deletion source/DasBlog.Web.UI/Themes/darkly/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -11080,7 +11080,7 @@ a.text-dark:hover, a.text-dark:focus {
}

.alert-info {
background-color: #3498DB
background-color: #00bc8c
}

.alert-warning {
Expand Down
2 changes: 2 additions & 0 deletions source/DasBlog.Web.UI/Themes/dasblog/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@

<div class="container body-content">

<partial name="_CookieConsentPartial" />

@RenderBody()

<div class="container text-center">
Expand Down
1 change: 1 addition & 0 deletions source/DasBlog.Web.UI/Themes/dasblog/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@
width: 100%;
height: 100%;
}

4 changes: 4 additions & 0 deletions source/DasBlog.Web.UI/Themes/fulcrum/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@
</div>

<div class="container body-content">

<partial name="_CookieConsentPartial" />

@RenderBody()

<footer>
<div class="col-12 text-center">
<site-copyright />
Expand Down
2 changes: 2 additions & 0 deletions source/DasBlog.Web.UI/Themes/journal/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

<div class="container body-content">

<partial name="_CookieConsentPartial" />

@RenderBody()

<div class="container text-center">
Expand Down
4 changes: 4 additions & 0 deletions source/DasBlog.Web.UI/Themes/median/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@
<div class="clear"></div>
</header>

<partial name="_CookieConsentPartial" />

<section class="row">

<div class="col-sm-12">
<section class="row">

<div class="col-md-12 col-lg-8">
@RenderBody()
</div>
Expand Down
4 changes: 4 additions & 0 deletions source/DasBlog.Web.UI/Themes/median/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -812,3 +812,7 @@ table, td, tr, th, thead {
background: #f7f7f7; }
.error-page h1 {
font-size: 4rem; }

.alert-info {
background-color: #7376df;
}
7 changes: 7 additions & 0 deletions source/DasBlog.Web.UI/Views/Admin/Settings.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,13 @@

</div>

<div class="dbc-form-check row">

@Html.LabelFor(m => @Model.SiteConfig.CookieConsentEnabled, null, new { @class = "dbc-col-form-label col-3" })
@Html.CheckBoxFor(m => @Model.SiteConfig.CookieConsentEnabled, new { @class = "dbc-form-check-input" })

</div>

<div class="dbc-form-check row">

@Html.LabelFor(m => @Model.SiteConfig.UseAspxExtension, null, new { @class = "dbc-col-form-label col-3" })
Expand Down
25 changes: 25 additions & 0 deletions source/DasBlog.Web.UI/Views/Shared/_CookieConsentPartial.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@using Microsoft.AspNetCore.Http.Features

@{
var consentFeature = Context.Features.Get<ITrackingConsentFeature>();
var showBanner = !consentFeature?.CanTrack ?? false;
var cookieString = consentFeature?.CreateConsentCookie();
}

@if (showBanner)
{
<div id="cookieConsent" class="alert alert-info alert-dismissible fade show" role="alert">
This website uses cookies to ensure you get the best experience on our website. <a href="http://cookiesandyou.com/">Learn More</a>.
<button type="button" class="accept-policy close" data-dismiss="alert" aria-label="Close" data-cookie-string="@cookieString">
<span aria-hidden="true">Accept</span>
</button>
</div>
<script>
(function () {
var button = document.querySelector("#cookieConsent button[data-cookie-string]");
button.addEventListener("click", function (event) {
document.cookie = button.dataset.cookieString;
}, false);
})();
</script>
}

0 comments on commit 1aff31d

Please sign in to comment.