From 088ce651c8dbeb79c3ef7f42553c625718a21c79 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Thu, 1 Sep 2016 09:05:20 +0200 Subject: [PATCH] Show global TermsAndConditions changed banner if member is logged in and has no date at which they accepted the terms of service --- OurUmbraco.Site/OurUmbraco.Site.csproj | 1 + .../MacroPartials/Global/AlertBar.cshtml | 2 + .../Community/TermsAndConditions.cshtml | 13 ++++++ .../TermsAndConditionsController.cs | 43 +++++++++++++++++++ .../Our/Models/TermsAndConditionsModel.cs | 7 +++ OurUmbraco/OurUmbraco.csproj | 2 + 6 files changed, 68 insertions(+) create mode 100644 OurUmbraco.Site/Views/Partials/Community/TermsAndConditions.cshtml create mode 100644 OurUmbraco/Our/Controllers/TermsAndConditionsController.cs create mode 100644 OurUmbraco/Our/Models/TermsAndConditionsModel.cs diff --git a/OurUmbraco.Site/OurUmbraco.Site.csproj b/OurUmbraco.Site/OurUmbraco.Site.csproj index 8d230464..6be59ffa 100644 --- a/OurUmbraco.Site/OurUmbraco.Site.csproj +++ b/OurUmbraco.Site/OurUmbraco.Site.csproj @@ -1755,6 +1755,7 @@ + diff --git a/OurUmbraco.Site/Views/MacroPartials/Global/AlertBar.cshtml b/OurUmbraco.Site/Views/MacroPartials/Global/AlertBar.cshtml index 3189e01d..6428e7c6 100644 --- a/OurUmbraco.Site/Views/MacroPartials/Global/AlertBar.cshtml +++ b/OurUmbraco.Site/Views/MacroPartials/Global/AlertBar.cshtml @@ -12,6 +12,8 @@ } } +@Html.Action("RenderTerms", "TermsAndConditions") + @* We'll show it differently on the homepage *@ @if (showNotification && Model.Content.Id != home.Id) { diff --git a/OurUmbraco.Site/Views/Partials/Community/TermsAndConditions.cshtml b/OurUmbraco.Site/Views/Partials/Community/TermsAndConditions.cshtml new file mode 100644 index 00000000..d9cb2523 --- /dev/null +++ b/OurUmbraco.Site/Views/Partials/Community/TermsAndConditions.cshtml @@ -0,0 +1,13 @@ +@using OurUmbraco.Our.Controllers +@model OurUmbraco.Our.Models.TermsAndConditionsModel +@if (Model.ShowTermsAndConditionsBanner) +{ +
+ Hi! Our terms and conditions for Our Umbraco have changed. Give them a read (we promise they're short).
+ Your continued use of this site after changes are posted constitutes your acceptance of the terms and conditions as modified.
+ @using (Html.BeginUmbracoForm("AcceptTerms")) + { + + } +
+} \ No newline at end of file diff --git a/OurUmbraco/Our/Controllers/TermsAndConditionsController.cs b/OurUmbraco/Our/Controllers/TermsAndConditionsController.cs new file mode 100644 index 00000000..ddcc28a2 --- /dev/null +++ b/OurUmbraco/Our/Controllers/TermsAndConditionsController.cs @@ -0,0 +1,43 @@ +using System; +using System.Web.Mvc; +using OurUmbraco.Our.Models; +using Umbraco.Web; +using Umbraco.Web.Mvc; + +namespace OurUmbraco.Our.Controllers +{ + public class TermsAndConditionsController : SurfaceController + { + [ChildActionOnly] + public ActionResult RenderTerms() + { + var model = new TermsAndConditionsModel(); + var currentMember = Members.GetCurrentMember(); + if (currentMember != null) + { + var tosAccepted = currentMember.GetPropertyValue("tos"); + var newTosDate = new DateTime(2016, 09, 01); + if ((newTosDate - tosAccepted).TotalDays > 1) + { + model.ShowTermsAndConditionsBanner = true; + } + } + + return PartialView("~/Views/Partials/Community/TermsAndConditions.cshtml", model); + } + + public ActionResult AcceptTerms() + { + var currentMember = Members.GetCurrentMember(); + if (currentMember != null) + { + var memberService = Services.MemberService; + var member = memberService.GetById(currentMember.Id); + member.SetValue("tos", DateTime.Now); + memberService.Save(member); + } + + return RedirectToCurrentUmbracoPage(); + } + } +} diff --git a/OurUmbraco/Our/Models/TermsAndConditionsModel.cs b/OurUmbraco/Our/Models/TermsAndConditionsModel.cs new file mode 100644 index 00000000..8be631a5 --- /dev/null +++ b/OurUmbraco/Our/Models/TermsAndConditionsModel.cs @@ -0,0 +1,7 @@ +namespace OurUmbraco.Our.Models +{ + public class TermsAndConditionsModel + { + public bool ShowTermsAndConditionsBanner { get; set; } + } +} diff --git a/OurUmbraco/OurUmbraco.csproj b/OurUmbraco/OurUmbraco.csproj index 91389b39..adb93def 100644 --- a/OurUmbraco/OurUmbraco.csproj +++ b/OurUmbraco/OurUmbraco.csproj @@ -415,6 +415,7 @@ + @@ -453,6 +454,7 @@ +