diff --git a/OurUmbraco.Site/OurUmbraco.Site.csproj b/OurUmbraco.Site/OurUmbraco.Site.csproj index 0357fa4d..42e87315 100644 --- a/OurUmbraco.Site/OurUmbraco.Site.csproj +++ b/OurUmbraco.Site/OurUmbraco.Site.csproj @@ -411,6 +411,8 @@ + + @@ -1698,7 +1700,6 @@ - @@ -4321,7 +4322,6 @@ - diff --git a/OurUmbraco.Site/Views/Community.cshtml b/OurUmbraco.Site/Views/Community.cshtml index d53eeff6..665cfed2 100644 --- a/OurUmbraco.Site/Views/Community.cshtml +++ b/OurUmbraco.Site/Views/Community.cshtml @@ -1,4 +1,4 @@ -@inherits UmbracoTemplatePage +@inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage @{ Layout = "~/Views/Master.cshtml"; } diff --git a/OurUmbraco.Site/Views/Forum.cshtml b/OurUmbraco.Site/Views/Forum.cshtml index 1e79c589..59caa2ce 100644 --- a/OurUmbraco.Site/Views/Forum.cshtml +++ b/OurUmbraco.Site/Views/Forum.cshtml @@ -6,7 +6,7 @@
- @Umbraco.RenderMacro("ForumForum") + @Html.Partial("~/Views/Partials/Forum/Forum.cshtml")
@Umbraco.RenderMacro("ForumForm") diff --git a/OurUmbraco.Site/Views/Master.cshtml b/OurUmbraco.Site/Views/Master.cshtml index 9cedfd8c..7ea8f82b 100644 --- a/OurUmbraco.Site/Views/Master.cshtml +++ b/OurUmbraco.Site/Views/Master.cshtml @@ -1,7 +1,6 @@ @using ClientDependency.Core.Mvc @using Umbraco.Core.Configuration -@using Umbraco.Web.Security -@inherits UmbracoTemplatePage +@inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage @{ Layout = null; var model = UmbracoContext.Current.PublishedContentRequest.PublishedContent; @@ -9,11 +8,8 @@ model.Level > 2 && model.AncestorOrSelf(3).Id == 1057 ? "profile has-sidebar" : model.DocumentTypeAlias.ToLower().Replace(" ", "-") + "-page"; - - var ms = new MembershipHelper(UmbracoContext.Current); - var member = ms.GetCurrentMember(); - var memberIsBlocked = false; - if (member != null) { memberIsBlocked = member.GetPropertyValue("blocked"); } + + var memberIsBlocked = MemberData != null && MemberData.IsBlocked; Html.RequiresCss("~/assets/css/style.min.css", 0); @@ -74,10 +70,10 @@ @{ var title = string.Empty; - var topicTitle = HttpContext.Current.Items["topicTitle"]; - if (topicTitle != null) + var navigationTitle = HttpContext.Current.Items["topicTitle"]; + if (navigationTitle != null) { - title = topicTitle.ToString(); + title = navigationTitle.ToString(); } if (string.IsNullOrWhiteSpace(title) == false) diff --git a/OurUmbraco.Site/Views/Partials/Community/Home.cshtml b/OurUmbraco.Site/Views/Partials/Community/Home.cshtml index 6e1e555d..a33f550c 100644 --- a/OurUmbraco.Site/Views/Partials/Community/Home.cshtml +++ b/OurUmbraco.Site/Views/Partials/Community/Home.cshtml @@ -1,8 +1,9 @@ -@inherits UmbracoViewPage<IPublishedContent> +@using OurUmbraco.Our.Models +@inherits OurUmbracoTemplatePage @{ - var homeNotificationText = Model.GetPropertyValue<string>("homeOnlyBanner"); + var homeNotificationText = Model.Content.GetPropertyValue<string>("homeOnlyBanner"); var showHomeNotification = string.IsNullOrWhiteSpace(homeNotificationText) == false; - var globalNotificationText = Model.GetPropertyValue<string>("mainNotification"); + var globalNotificationText = Model.Content.GetPropertyValue<string>("mainNotification"); var showGlobalNotification = string.IsNullOrWhiteSpace(globalNotificationText) == false; } <!-- Search start --> @@ -20,7 +21,7 @@ <ul></ul> </div> - @if (!Members.IsLoggedIn()) + @if (MemberData == null) { <div class="search-text"> <div class="container"> diff --git a/OurUmbraco.Site/Views/Partials/Community/JsValues.cshtml b/OurUmbraco.Site/Views/Partials/Community/JsValues.cshtml index 0a3063c6..a067f354 100644 --- a/OurUmbraco.Site/Views/Partials/Community/JsValues.cshtml +++ b/OurUmbraco.Site/Views/Partials/Community/JsValues.cshtml @@ -1,37 +1,11 @@ -@using OurUmbraco.Forum.Extensions -@using Umbraco.Core.Cache -@inherits UmbracoViewPage<IPublishedContent> -@{ - MemberJsValues memberJsValues = null; - if (Members.IsLoggedIn()) - { - var userName = Members.CurrentUserName; - if (userName != null) - { - memberJsValues = ApplicationContext.ApplicationCache.RuntimeCache - .GetCacheItem<MemberJsValues>("MemberJsValues" + userName, - () => - { - var profile = Members.GetCurrentMemberProfileModel(); - var member = Members.GetCurrentMember(); +@inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage - return new MemberJsValues - { - Name = member.Name, - Email = profile.Email, - Icon = member.Avatar() - }; - }, TimeSpan.FromMinutes(30), true); - } - } -} - -@if (memberJsValues != null) +@if (MemberData != null) { <script type="text/javascript"> - var umb_member_name = '@memberJsValues.Name'; - var umb_member_email = '@memberJsValues.Email'; - var umb_member_icon = '@memberJsValues.Icon'; + var umb_member_name = '@MemberData.Member.Name'; + var umb_member_email = '@MemberData.Email'; + var umb_member_icon = '@MemberData.AvatarPath'; </script> } diff --git a/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml b/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml index c38ac387..91286fd5 100644 --- a/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml +++ b/OurUmbraco.Site/Views/Partials/Community/Scripts.cshtml @@ -1,17 +1,17 @@ <script type="text/javascript"> - $(document).ready(function () { - try { - $("#twitter-search").load("@Url.Action("TwitterSearchResult", "TwitterSearch", new { numberOfResults = 6 })"); - } - catch (errTwitter) { - console.log("Couldn't load Twitter feed", errTwitter.message); - } + $(document).ready(function () { + try { + $("#twitter-search").load("@Url.Action("TwitterSearchResult", "TwitterSearch", new { numberOfResults = 6 })"); + } + catch (errTwitter) { + console.log("Couldn't load Twitter feed", errTwitter.message); + } - try { - $("#forum-activity").load("@Url.Action("LatestActivity", "LatestActivity", new { numberOfTopics = 6 })"); - } - catch (errForum) { - console.log("Couldn't load latest forum activity", errForum.message); - } - }); + try { + $("#forum-activity").load("@Url.Action("LatestActivity", "LatestActivity", new { numberOfTopics = 6 })"); + } + catch (errForum) { + console.log("Couldn't load latest forum activity", errForum.message); + } + }); </script> \ No newline at end of file diff --git a/OurUmbraco.Site/Views/MacroPartials/Forum/Forum.cshtml b/OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml similarity index 95% rename from OurUmbraco.Site/Views/MacroPartials/Forum/Forum.cshtml rename to OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml index f816e318..ca947ed0 100644 --- a/OurUmbraco.Site/Views/MacroPartials/Forum/Forum.cshtml +++ b/OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml @@ -1,195 +1,195 @@ -@using OurUmbraco.Forum.Extensions -@using OurUmbraco.Forum.Library -@using OurUmbraco.Forum.Models -@using OurUmbraco.Forum.Services -@inherits Umbraco.Web.Macros.PartialViewMacroPage - -@{ - const int pagesToShowLeft = 4; - int page; - if (!int.TryParse(Request["page"], out page)) - { - page = 1; - } - bool unsolved; - bool.TryParse(Request["unsolved"], out unsolved); - bool noreplies; - bool.TryParse(Request["noreplies"], out noreplies); - - var cat = -1; - if (CurrentPage.Level > 2) - { - cat = CurrentPage.Id; - } - var topicService = new TopicService(ApplicationContext.DatabaseContext); - - IEnumerable<ReadOnlyTopic> topics; - - var cache = ApplicationContext.Current.ApplicationCache.RuntimeCache; - // only cache the first page of each category - var pageSize = 50; - if (page > 1) - { - topics = topicService.GetLatestTopicsFiltered(pageSize, page, true, cat, unsolved, noreplies); - } - else - { - var key = "OurForumForum[" + cat + unsolved + noreplies + "]"; - topics = (IEnumerable<ReadOnlyTopic>)cache.GetCacheItem(key, - () => topicService.GetLatestTopicsFiltered(pageSize, page, true, cat, unsolved, noreplies).ToArray(), - TimeSpan.FromSeconds(4)); - } - - var totalCountKey = "OurForumForumThreadCount[" + cat + "]"; - var totalTopics = (int)cache.GetCacheItem(totalCountKey, - () => topicService.GetAllTopicsCount(cat), - TimeSpan.FromMinutes(1)); - - var pages = (totalTopics / pageSize) + 1; - - var categories = Model.Content.AncestorOrSelf(2); -} -@if (Model.Content.NewTopicsAllowed() == false || Model.Content.AncestorOrSelfIsArchived()) -{ - var notification = Model.Content.GetPropertyValue<string>("mainNotification"); - if (string.IsNullOrWhiteSpace(notification)) - { - notification = "This forum is in read only mode, you can no longer create new topics"; - } - - <div class="alertbar__yellow"> - @Html.Raw(notification) - </div> -} -<!-- FORUM HEADER START --> -<div class="utilities"> - - @Umbraco.RenderMacro("Breadcrumb", new { linktocurrent = "1" }) - - @Umbraco.RenderMacro("ForumForumActions") - -</div> - -<div class="forum-settings"> - <div class="search-big"> - <input type="search" class="forum-search-input" required placeholder="Search for threads"> - <label for="search">Search for threads</label> - </div> - - <div class="or">or</div> - <div class="sorting"> - <select id="selectCategory" data-placeholder="Choose…"> - <option class="category" selected disabled>Filter by category</option> - @if (categories.ContentType.Alias == "Projects") - { - foreach (var tag in CurrentPage.Parent.Children) - { - <option class="@tag.Name.ToLower().Replace(" ", "")" value="@tag.Id" @(CurrentPage.Id == tag.Id ? "selected" : null)>@tag.Name</option> - } - } - else - { - <option class="all" value="@categories.Id">All categories</option> - foreach (var tag in categories.Children) - { - if (tag.ContentType.Alias == "Forum" && tag.IsArchived() == false) - { - <option class="@tag.Name.ToLower().Replace(" ", "")" value="@tag.Id" @(CurrentPage.Id == tag.Id ? "selected" : null)>@tag.Name</option> - } - } - } - </select> - </div> - - <div id="search-options" class="search-options"> - <label>Filter by</label> - <div class="options"> - - <label class="checkbox"> - <input type="checkbox" name="unsolved" /> - <span></span> - <small>show only unsolved topics</small> - </label> - - - <label class="checkbox"> - <input type="checkbox" name="noreplies" /> - <span></span> - <small>show only topics with no replies</small> - </label> - - </div> - </div> -</div> - -<!-- FORUM HEADER END --> -<!-- FORUM TOPICS --> -<div id="overlay" class="overlay"></div> -<!-- FORUM LIST START --> -<section class="forum"> - <!-- FORUM LIST HEADER START --> - <div class="forum-head"> - - <div class="topic">Topic</div> - <div class="category">Category</div> - <div class="posts">Replies</div> - - </div> - <!-- FORUM LIST HEADER END --> - <!-- FORUM LIST OF THREADS START --> - <div class="forum-content"> - - <!-- FORUM THREAD START --> - @foreach (var topic in topics) - { - var forum = Umbraco.TypedContent(topic.ParentId); - if (forum != null) - { - <div class="topic-row @Umbraco.If(topic.Answer > 0, " solved")"> - - <div class="topic"> - <a href="@topic.GetUrl()"> - <h3>@topic.Title</h3> - @if (topic.Replies != 0 && !string.IsNullOrEmpty(topic.LastReplyAuthorName)) - { - <span title="@string.Format("{0:ddd, dd MMM yyyy} {0:HH:mm:ss} UTC+{1}", topic.Updated, TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now))">last edited by <strong>@topic.LastReplyAuthorName</strong> @topic.Updated.ConvertToRelativeTime()</span> - } - else - { - <span title="@string.Format("{0:ddd, dd MMM yyyy} {0:HH:mm:ss} UTC+{1}", topic.Updated, TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now))">topic created by <strong>@topic.AuthorName</strong> @topic.Updated.ConvertToRelativeTime()</span> - } - </a> - </div> - <div class="category frontend"> - <a href="@forum.Url">@(Utils.GetForumName(forum))</a> - </div> - <div class="posts"><small>@topic.Replies</small> <span>replies</span></div> - </div> - } - } - - <nav class="pagination" role="navigation"> - @if (page > 1) - { - <a class="prev" href="?page=@(page - 1)">Prev</a> - <span>…</span> - } - - @for (var i = (page - 1 > 0 ? page - 1 : 1); i < (page + (pagesToShowLeft - (page - 1 > 0 ? 1 : 0))) && i <= pages; i++) - { - <a class="@Umbraco.If(i == page, "active")" href="?page=@i">@i</a> - } - - @if (page < (pages - 3)) - { - <span>…</span> - <a class="next" href="?page=@(page + 1)">Next</a> - } - </nav> - - </div> - - - <div class="forum-conten"></div> - <!-- FORUM LIST OF THREADS START --> -</section> +@using OurUmbraco.Forum.Extensions +@using OurUmbraco.Forum.Library +@using OurUmbraco.Forum.Models +@using OurUmbraco.Forum.Services +@inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage + +@{ + const int pagesToShowLeft = 4; + int page; + if (!int.TryParse(Request["page"], out page)) + { + page = 1; + } + bool unsolved; + bool.TryParse(Request["unsolved"], out unsolved); + bool noreplies; + bool.TryParse(Request["noreplies"], out noreplies); + + var cat = -1; + if (CurrentPage.Level > 2) + { + cat = CurrentPage.Id; + } + var topicService = new TopicService(ApplicationContext.DatabaseContext); + + IEnumerable<ReadOnlyTopic> topics; + + var cache = ApplicationContext.Current.ApplicationCache.RuntimeCache; + // only cache the first page of each category + var pageSize = 50; + if (page > 1) + { + topics = topicService.GetLatestTopicsFiltered(pageSize, page, true, cat, unsolved, noreplies); + } + else + { + var key = "OurForumForum[" + cat + unsolved + noreplies + "]"; + topics = (IEnumerable<ReadOnlyTopic>)cache.GetCacheItem(key, + () => topicService.GetLatestTopicsFiltered(pageSize, page, true, cat, unsolved, noreplies).ToArray(), + TimeSpan.FromSeconds(4)); + } + + var totalCountKey = "OurForumForumThreadCount[" + cat + "]"; + var totalTopics = (int)cache.GetCacheItem(totalCountKey, + () => topicService.GetAllTopicsCount(cat), + TimeSpan.FromMinutes(1)); + + var pages = (totalTopics / pageSize) + 1; + + var categories = Model.Content.AncestorOrSelf(2); +} +@if (Model.Content.NewTopicsAllowed() == false || Model.Content.AncestorOrSelfIsArchived()) +{ + var notification = Model.Content.GetPropertyValue<string>("mainNotification"); + if (string.IsNullOrWhiteSpace(notification)) + { + notification = "This forum is in read only mode, you can no longer create new topics"; + } + + <div class="alertbar__yellow"> + @Html.Raw(notification) + </div> +} +<!-- FORUM HEADER START --> +<div class="utilities"> + + @Umbraco.RenderMacro("Breadcrumb", new { linktocurrent = "1" }) + + @Html.Partial("~/Views/Partials/Forum/ForumActions.cshtml") + +</div> + +<div class="forum-settings"> + <div class="search-big"> + <input type="search" class="forum-search-input" required placeholder="Search for threads"> + <label for="search">Search for threads</label> + </div> + + <div class="or">or</div> + <div class="sorting"> + <select id="selectCategory" data-placeholder="Choose…"> + <option class="category" selected disabled>Filter by category</option> + @if (categories.ContentType.Alias == "Projects") + { + foreach (var tag in CurrentPage.Parent.Children) + { + <option class="@tag.Name.ToLower().Replace(" ", "")" value="@tag.Id" @(CurrentPage.Id == tag.Id ? "selected" : null)>@tag.Name</option> + } + } + else + { + <option class="all" value="@categories.Id">All categories</option> + foreach (var tag in categories.Children) + { + if (tag.ContentType.Alias == "Forum" && tag.IsArchived() == false) + { + <option class="@tag.Name.ToLower().Replace(" ", "")" value="@tag.Id" @(CurrentPage.Id == tag.Id ? "selected" : null)>@tag.Name</option> + } + } + } + </select> + </div> + + <div id="search-options" class="search-options"> + <label>Filter by</label> + <div class="options"> + + <label class="checkbox"> + <input type="checkbox" name="unsolved" /> + <span></span> + <small>show only unsolved topics</small> + </label> + + + <label class="checkbox"> + <input type="checkbox" name="noreplies" /> + <span></span> + <small>show only topics with no replies</small> + </label> + + </div> + </div> +</div> + +<!-- FORUM HEADER END --> +<!-- FORUM TOPICS --> +<div id="overlay" class="overlay"></div> +<!-- FORUM LIST START --> +<section class="forum"> + <!-- FORUM LIST HEADER START --> + <div class="forum-head"> + + <div class="topic">Topic</div> + <div class="category">Category</div> + <div class="posts">Replies</div> + + </div> + <!-- FORUM LIST HEADER END --> + <!-- FORUM LIST OF THREADS START --> + <div class="forum-content"> + + <!-- FORUM THREAD START --> + @foreach (var topic in topics) + { + var forum = Umbraco.TypedContent(topic.ParentId); + if (forum != null) + { + <div class="topic-row @Umbraco.If(topic.Answer > 0, " solved")"> + + <div class="topic"> + <a href="@topic.GetUrl()"> + <h3>@topic.Title</h3> + @if (topic.Replies != 0 && !string.IsNullOrEmpty(topic.LastReplyAuthorName)) + { + <span title="@string.Format("{0:ddd, dd MMM yyyy} {0:HH:mm:ss} UTC+{1}", topic.Updated, TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now))">last edited by <strong>@topic.LastReplyAuthorName</strong> @topic.Updated.ConvertToRelativeTime()</span> + } + else + { + <span title="@string.Format("{0:ddd, dd MMM yyyy} {0:HH:mm:ss} UTC+{1}", topic.Updated, TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now))">topic created by <strong>@topic.AuthorName</strong> @topic.Updated.ConvertToRelativeTime()</span> + } + </a> + </div> + <div class="category frontend"> + <a href="@forum.Url">@(Utils.GetForumName(forum))</a> + </div> + <div class="posts"><small>@topic.Replies</small> <span>replies</span></div> + </div> + } + } + + <nav class="pagination" role="navigation"> + @if (page > 1) + { + <a class="prev" href="?page=@(page - 1)">Prev</a> + <span>…</span> + } + + @for (var i = (page - 1 > 0 ? page - 1 : 1); i < (page + (pagesToShowLeft - (page - 1 > 0 ? 1 : 0))) && i <= pages; i++) + { + <a class="@Umbraco.If(i == page, "active")" href="?page=@i">@i</a> + } + + @if (page < (pages - 3)) + { + <span>…</span> + <a class="next" href="?page=@(page + 1)">Next</a> + } + </nav> + + </div> + + + <div class="forum-conten"></div> + <!-- FORUM LIST OF THREADS START --> +</section> diff --git a/OurUmbraco.Site/Views/MacroPartials/Forum/ForumActions.cshtml b/OurUmbraco.Site/Views/Partials/Forum/ForumActions.cshtml similarity index 76% rename from OurUmbraco.Site/Views/MacroPartials/Forum/ForumActions.cshtml rename to OurUmbraco.Site/Views/Partials/Forum/ForumActions.cshtml index efd1e1e6..3fcd78ad 100644 --- a/OurUmbraco.Site/Views/MacroPartials/Forum/ForumActions.cshtml +++ b/OurUmbraco.Site/Views/Partials/Forum/ForumActions.cshtml @@ -1,9 +1,9 @@ -@using OurUmbraco.Forum.Extensions +@using OurUmbraco.Forum.Extensions @using OurUmbraco.NotificationsWeb.Library -@inherits Umbraco.Web.Macros.PartialViewMacroPage +@inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage <div class="utility-actions"> - @if (Members.IsLoggedIn()) + @if (MemberData != null) { if (Model.Content.AncestorOrSelfIsArchived() == false && Model.Content.NewTopicsAllowed()) { @@ -12,13 +12,7 @@ </a> } - var mem = Members.GetCurrentMember(); - var subscribed = false; - if (mem != null) - { - subscribed = Utils.IsSubscribedToForum(CurrentPage.Id, mem.Id); - } - + var subscribed = Utils.IsSubscribedToForum(CurrentPage.Id, MemberData.Member.Id); if (subscribed) { <a href="#" class="follow button following" data-id="@CurrentPage.Id" data-controller=""> diff --git a/OurUmbraco.Site/Views/Partials/Global/Alertbar.cshtml b/OurUmbraco.Site/Views/Partials/Global/Alertbar.cshtml index 8992d8dd..7ef20198 100644 --- a/OurUmbraco.Site/Views/Partials/Global/Alertbar.cshtml +++ b/OurUmbraco.Site/Views/Partials/Global/Alertbar.cshtml @@ -1,28 +1,21 @@ -@using System.Drawing -@using OurUmbraco.Our -@inherits UmbracoViewPage<IPublishedContent> +@inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage @{ var home = Umbraco.TypedContentAtRoot().First(); var notificationText = home.GetPropertyValue<string>("mainNotification"); var showNotification = string.IsNullOrWhiteSpace(notificationText) == false; - Image avatarImage = null; - if (Members.IsLoggedIn()) - { - avatarImage = Utils.GetMemberAvatarImage(Members.GetCurrentMember()); - } } -@Html.Action("RenderTerms", "TermsAndConditions") +@Html.Action("RenderTerms", "TermsAndConditions", new { showBanner = MemberData != null && MemberData.NewTosAccepted == false }) @* We'll show it differently on the homepage *@ -@if (showNotification && Model.Id != home.Id) +@if (showNotification && Model.Content.Id != home.Id) { <div class="alertbar__yellow"> @Html.Raw(notificationText) </div> } -@if (Request.Cookies["dismissAvatar"] == null && Model.Id != home.Id && avatarImage != null && (avatarImage.Width < 400 || avatarImage.Height < 400)) +@if (Request.Cookies["dismissAvatar"] == null && Model.Content.Id != home.Id && MemberData != null && MemberData.AvatarImageTooSmall) { <div class="notification__blue avatarTooSmall"> <div class="message text-center"> diff --git a/OurUmbraco.Site/Views/Partials/Members/QuickMenu.cshtml b/OurUmbraco.Site/Views/Partials/Members/QuickMenu.cshtml index 6efcfa87..88e3c982 100644 --- a/OurUmbraco.Site/Views/Partials/Members/QuickMenu.cshtml +++ b/OurUmbraco.Site/Views/Partials/Members/QuickMenu.cshtml @@ -1,66 +1,7 @@ -@inherits UmbracoViewPage<IPublishedContent> -@using System.Drawing +@inherits OurUmbracoTemplatePage @using OurUmbraco.Forum.Extensions -@using OurUmbraco.Forum.Models -@using OurUmbraco.Forum.Services -@using OurUmbraco.Our -@using Umbraco.Core.Cache -@{ - MemberData profile = null; - if (Members.IsLoggedIn()) - { - var userName = Members.CurrentUserName; - - profile = ApplicationContext.ApplicationCache.RuntimeCache - .GetCacheItem<MemberData>("MemberData" + userName, - GetMemberData, TimeSpan.FromMinutes(5)); - } -} - -@functions -{ - public class MemberData - { - public int Id { get; set; } - public string Name { get; set; } - public string TwitterHandle { get; set; } - public int Karma { get; set; } - public bool IsAdmin { get; set; } - public IEnumerable<string> Roles { get; set; } - public IEnumerable<ReadOnlyTopic> LatestTopics { get; set; } - public int NumberOfForumPosts { get; set; } - public string Avatar { get; set; } - public Image AvatarImage { get; set; } - } - - public MemberData GetMemberData() - { - var member = Members.GetCurrentMember(); - var avatarImage = Utils.GetMemberAvatarImage(member); - - var roles = member.GetRoles(); - - var topicService = new TopicService(ApplicationContext.DatabaseContext); - var latestTopics = topicService.GetLatestTopicsForMember(member.Id, maxCount: 100); - - var memberData = new MemberData - { - Id = member.Id, - Name = member.Name, - AvatarImage = avatarImage, - Roles = roles, - LatestTopics = latestTopics, - Avatar = Utils.GetMemberAvatar(member, 100), - NumberOfForumPosts = member.ForumPosts(), - Karma = member.Karma(), - TwitterHandle = member.GetPropertyValue<string>("twitter").Replace("@", string.Empty), - IsAdmin = member.IsAdmin() - }; - - return memberData; - } -} - +@using OurUmbraco.Our.Models +@{ var profile = MemberData; } <div class="quick-menu"> <div class="container"> <div class="row"> @@ -75,11 +16,11 @@ </div> <div class="user-image"> - @Html.Raw(profile.Avatar) + @Html.Raw(profile.AvatarHtml) </div> <div class="user-profile"> - <h2>@profile.Name</h2> + <h2>@profile.Member.Name</h2> <div class="posts"> @profile.NumberOfForumPosts @@ -112,7 +53,7 @@ </span> } <div class="public-profile"> - <a href="/member/@profile.Id">View my public profile</a> + <a href="/member/@profile.Member.Id">View my public profile</a> </div> @if (profile.IsAdmin) { @@ -125,7 +66,7 @@ </div> </div> - if (profile.AvatarImage != null && (profile.AvatarImage.Width < 400 || profile.AvatarImage.Height < 400)) + if (profile.AvatarImageTooSmall) { <div class="user-notifications"> <small> diff --git a/OurUmbraco.Site/Views/Partials/Navigation/TopNavigation.cshtml b/OurUmbraco.Site/Views/Partials/Navigation/TopNavigation.cshtml index 35a502f6..43fcabdf 100644 --- a/OurUmbraco.Site/Views/Partials/Navigation/TopNavigation.cshtml +++ b/OurUmbraco.Site/Views/Partials/Navigation/TopNavigation.cshtml @@ -1,32 +1,18 @@ -@using System.Drawing -@using OurUmbraco.Our -@inherits UmbracoViewPage<IPublishedContent> - -@{ - @* Get the root of the website *@ -var root = Model.AncestorOrSelf(1); -Image avatarImage = null; -if (Members.IsLoggedIn()) -{ - avatarImage = Utils.GetMemberAvatarImage(Members.GetCurrentMember()); -} -} - +@inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage <ul> - @foreach (var page in root.Children.Where("Visible")) + @foreach (var page in Model.Content.AncestorOrSelf(1).Children.Where("Visible")) { - <li class="@(page.IsAncestorOrSelf(Model) ? "current" : null)"> + <li class="@(page.IsAncestorOrSelf(Model.Content) ? "current" : null)"> <a href="@page.Url">@page.Name</a> </li> } <li> - @if (Members.IsLoggedIn() && Members.GetCurrentMember() != null) + @if (MemberData != null) { - var member = Members.GetCurrentMember(); <div class="user"> - @Html.Raw(Utils.GetMemberAvatar(member, 75)) - @if (avatarImage != null && (avatarImage.Width < 400 || avatarImage.Height < 400)) + @Html.Raw(MemberData.AvatarHtml) + @if (MemberData.AvatarImageTooSmall) { <span class="notificationCount">1</span> } diff --git a/OurUmbraco/Our/Controllers/OurUmbracoController.cs b/OurUmbraco/Our/Controllers/OurUmbracoController.cs new file mode 100644 index 00000000..6cfa4804 --- /dev/null +++ b/OurUmbraco/Our/Controllers/OurUmbracoController.cs @@ -0,0 +1,9 @@ +using Umbraco.Web.Mvc; + +namespace OurUmbraco.Our.Controllers +{ + public sealed class OurUmbracoController : RenderMvcController + { + public OurUmbracoController() { } + } +} diff --git a/OurUmbraco/Our/Controllers/ProfileController.cs b/OurUmbraco/Our/Controllers/ProfileController.cs index ac76b768..9007faf2 100644 --- a/OurUmbraco/Our/Controllers/ProfileController.cs +++ b/OurUmbraco/Our/Controllers/ProfileController.cs @@ -32,16 +32,16 @@ namespace OurUmbraco.Our.Controllers var ms = Services.MemberService; var mem = ms.GetById(Members.GetCurrentMemberId()); - + if (mem.Email != model.Email && ms.GetByEmail(model.Email) != null) { ModelState.AddModelError("Email", "A Member with that email already exists"); return CurrentUmbracoPage(); - - } - if(model.Password != model.RepeatPassword) + var memberPreviousUserName = mem.Username; + + if (model.Password != model.RepeatPassword) { ModelState.AddModelError("Password", "Passwords need to match"); ModelState.AddModelError("RepeatPassword", "Passwords need to match"); @@ -66,10 +66,12 @@ namespace OurUmbraco.Our.Controllers } if(!string.IsNullOrEmpty(model.Password) && !string.IsNullOrEmpty(model.RepeatPassword) && model.Password == model.RepeatPassword) - ms.SavePassword(mem, model.Password); - + ms.SavePassword(mem, model.Password); + ApplicationContext.ApplicationCache.RuntimeCache.ClearCacheItem("MemberData" + memberPreviousUserName); + TempData["success"] = true; + return RedirectToCurrentUmbracoPage(); } } diff --git a/OurUmbraco/Our/Controllers/TermsAndConditionsController.cs b/OurUmbraco/Our/Controllers/TermsAndConditionsController.cs index ddcc28a2..8aa90279 100644 --- a/OurUmbraco/Our/Controllers/TermsAndConditionsController.cs +++ b/OurUmbraco/Our/Controllers/TermsAndConditionsController.cs @@ -1,7 +1,6 @@ using System; using System.Web.Mvc; using OurUmbraco.Our.Models; -using Umbraco.Web; using Umbraco.Web.Mvc; namespace OurUmbraco.Our.Controllers @@ -9,20 +8,9 @@ namespace OurUmbraco.Our.Controllers public class TermsAndConditionsController : SurfaceController { [ChildActionOnly] - public ActionResult RenderTerms() + public ActionResult RenderTerms(bool showBanner) { - var model = new TermsAndConditionsModel(); - var currentMember = Members.GetCurrentMember(); - if (currentMember != null) - { - var tosAccepted = currentMember.GetPropertyValue<DateTime>("tos"); - var newTosDate = new DateTime(2016, 09, 01); - if ((newTosDate - tosAccepted).TotalDays > 1) - { - model.ShowTermsAndConditionsBanner = true; - } - } - + var model = new TermsAndConditionsModel { ShowTermsAndConditionsBanner = showBanner }; return PartialView("~/Views/Partials/Community/TermsAndConditions.cshtml", model); } @@ -35,6 +23,7 @@ namespace OurUmbraco.Our.Controllers var member = memberService.GetById(currentMember.Id); member.SetValue("tos", DateTime.Now); memberService.Save(member); + ApplicationContext.ApplicationCache.RuntimeCache.ClearCacheItem("MemberData" + member.Username); } return RedirectToCurrentUmbracoPage(); diff --git a/OurUmbraco/Our/CustomHandlers/OurApplicationStartupHandler.cs b/OurUmbraco/Our/CustomHandlers/OurApplicationStartupHandler.cs index d1a163cd..b3c7845c 100644 --- a/OurUmbraco/Our/CustomHandlers/OurApplicationStartupHandler.cs +++ b/OurUmbraco/Our/CustomHandlers/OurApplicationStartupHandler.cs @@ -4,9 +4,10 @@ using Examine; using Examine.LuceneEngine.Providers; using OurUmbraco.Documentation.Busineslogic; using OurUmbraco.Documentation.Busineslogic.GithubSourcePull; +using OurUmbraco.Our.Controllers; using OurUmbraco.Our.Examine; using Umbraco.Core; -using Umbraco.Web; +using Umbraco.Web.Mvc; namespace OurUmbraco.Our.CustomHandlers { @@ -22,7 +23,12 @@ namespace OurUmbraco.Our.CustomHandlers ZipDownloader.OnFinish += ZipDownloader_OnFinish; FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); } - + + protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + DefaultRenderMvcControllerResolver.Current.SetDefaultControllerType(typeof(OurUmbracoController)); + } + private void BindExamineEvents() { var projectIndexer = (LuceneIndexer)ExamineManager.Instance.IndexProviderCollection["projectIndexer"]; diff --git a/OurUmbraco/Our/Models/MemberData.cs b/OurUmbraco/Our/Models/MemberData.cs new file mode 100644 index 00000000..8f537d99 --- /dev/null +++ b/OurUmbraco/Our/Models/MemberData.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using System.Drawing; +using OurUmbraco.Forum.Models; +using Umbraco.Core.Models; + +namespace OurUmbraco.Our.Models +{ + public class MemberData + { + public IPublishedContent Member { get; set; } + public string Email { get; set; } + public string TwitterHandle { get; set; } + public int Karma { get; set; } + public bool IsAdmin { get; set; } + public IEnumerable<string> Roles { get; set; } + public IEnumerable<ReadOnlyTopic> LatestTopics { get; set; } + public int NumberOfForumPosts { get; set; } + public string AvatarHtml { get; set; } + public string AvatarPath { get; set; } + public Image AvatarImage { get; set; } + public bool AvatarImageTooSmall { get; set; } + public bool IsBlocked { get; set; } + public bool NewTosAccepted { get; set; } + } +} diff --git a/OurUmbraco/Our/Models/OurUmbracoTemplatePage.cs b/OurUmbraco/Our/Models/OurUmbracoTemplatePage.cs new file mode 100644 index 00000000..e0a3b25d --- /dev/null +++ b/OurUmbraco/Our/Models/OurUmbracoTemplatePage.cs @@ -0,0 +1,72 @@ +using System; +using OurUmbraco.Forum.Extensions; +using OurUmbraco.Forum.Services; +using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Web; +using Umbraco.Web.Mvc; + +namespace OurUmbraco.Our.Models +{ + public class OurUmbracoTemplatePage : UmbracoTemplatePage + { + public MemberData MemberData; + + public OurUmbracoTemplatePage() + { + MemberData = GetMemberData(); + } + + public override void Execute() + { + } + + private static MemberData GetMemberData() + { + var membershipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); + + if (membershipHelper.IsLoggedIn() == false) return null; + + var userName = membershipHelper.CurrentUserName; + var memberData = ApplicationContext.Current.ApplicationCache.RuntimeCache + .GetCacheItem<MemberData>("MemberData" + userName, () => + { + var member = membershipHelper.GetCurrentMember(); + var avatarImage = Utils.GetMemberAvatarImage(member); + + var roles = member.GetRoles(); + + var topicService = new TopicService(ApplicationContext.Current.DatabaseContext); + var latestTopics = topicService.GetLatestTopicsForMember(member.Id, maxCount: 100); + + var newTosAccepted = true; + var tosAccepted = member.GetPropertyValue<DateTime>("tos"); + var newTosDate = new DateTime(2016, 09, 01); + if ((newTosDate - tosAccepted).TotalDays > 1) + newTosAccepted = false; + + var data = new MemberData + { + Member = member, + AvatarImage = avatarImage, + AvatarImageTooSmall = avatarImage != null && (avatarImage.Width < 400 || avatarImage.Height < 400), + Roles = roles, + LatestTopics = latestTopics, + AvatarHtml = Utils.GetMemberAvatar(member, 100), + AvatarPath = member.Avatar(), + NumberOfForumPosts = member.ForumPosts(), + Karma = member.Karma(), + TwitterHandle = member.GetPropertyValue<string>("twitter").Replace("@", string.Empty), + IsAdmin = member.IsAdmin(), + Email = member.GetPropertyValue<string>("Email"), + IsBlocked = member.GetPropertyValue<bool>("blocked"), + NewTosAccepted = newTosAccepted + }; + + return data; + }, TimeSpan.FromMinutes(5)); + + return memberData; + } + } +} diff --git a/OurUmbraco/OurUmbraco.csproj b/OurUmbraco/OurUmbraco.csproj index 3c0b2a1b..292750da 100644 --- a/OurUmbraco/OurUmbraco.csproj +++ b/OurUmbraco/OurUmbraco.csproj @@ -510,10 +510,12 @@ <Compile Include="Our\Api\YouTrackApiController.cs" /> <Compile Include="Our\Businesslogic\ProjectContributor.cs" /> <Compile Include="Our\Controllers\AvatarController.cs" /> + <Compile Include="Our\Controllers\OurUmbracoController.cs" /> <Compile Include="Our\Models\EditScreenshotModel.cs" /> <Compile Include="Our\Models\EditFileModel.cs" /> <Compile Include="Our\Models\EditProjectModel.cs" /> <Compile Include="Our\Controllers\LoginController.cs" /> + <Compile Include="Our\Models\MemberData.cs" /> <Compile Include="Our\Models\MyProjectsModel.cs" /> <Compile Include="Our\Controllers\ProfileController.cs" /> <Compile Include="Our\Controllers\ProfileNotificationController.cs" /> @@ -555,6 +557,7 @@ <SubType>ASPXCodeBehind</SubType> </Compile> <Compile Include="Our\MigrationsHandler.cs" /> + <Compile Include="Our\Models\OurUmbracoTemplatePage.cs" /> <Compile Include="Our\Models\ProfileModel.cs" /> <Compile Include="Our\Models\ProfileNotificationModel.cs" /> <Compile Include="Our\Models\ProjectCompleteModel.cs" />