From 264c537b50a881c12c8ae56f3c3c548b1c2ab9f1 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 27 Mar 2014 16:52:43 +1100 Subject: [PATCH] Fixes: U4-4530 Edit Profile Snippet: Check for null before loop --- src/Umbraco.Tests/Umbraco.Tests.csproj | 2 +- .../Templates/EditProfile.cshtml | 2 +- src/Umbraco.Web/Security/MembershipHelper.cs | 33 +++++++++++++++---- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 492783e0e8..4be38487bd 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -283,7 +283,7 @@ - + diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/EditProfile.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/EditProfile.cshtml index 8618e66162..eef8f5a911 100644 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/EditProfile.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/EditProfile.cshtml @@ -20,7 +20,7 @@ @*NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed*@ @Html.RenderJsHere() -@if (Members.IsLoggedIn()) +@if (Members.IsLoggedIn() && profileModel != null) { if (success) { diff --git a/src/Umbraco.Web/Security/MembershipHelper.cs b/src/Umbraco.Web/Security/MembershipHelper.cs index 2691f1d36c..abb2e90800 100644 --- a/src/Umbraco.Web/Security/MembershipHelper.cs +++ b/src/Umbraco.Web/Security/MembershipHelper.cs @@ -277,8 +277,15 @@ namespace Umbraco.Web.Security { var membershipUser = provider.GetCurrentUser(); var member = GetCurrentMember(); - //this shouldn't happen - if (member == null) return null; + //this shouldn't happen but will if the member is deleted in the back office while the member is trying + // to use the front-end! + if (member == null) + { + //log them out since they've been removed + FormsAuthentication.SignOut(); + + return null; + } var model = ProfileModel.CreateModel(); model.Name = member.Name; @@ -417,8 +424,15 @@ namespace Umbraco.Web.Security if (provider.IsUmbracoMembershipProvider()) { var member = GetCurrentMember(); - //this shouldn't happen - if (member == null) return model; + //this shouldn't happen but will if the member is deleted in the back office while the member is trying + // to use the front-end! + if (member == null) + { + //log them out since they've been removed + FormsAuthentication.SignOut(); + model.IsLoggedIn = false; + return model; + } model.Name = member.Name; model.Username = member.Username; model.Email = member.Email; @@ -426,8 +440,15 @@ namespace Umbraco.Web.Security else { var member = provider.GetCurrentUser(); - //this shouldn't happen - if (member == null) return null; + //this shouldn't happen but will if the member is deleted in the back office while the member is trying + // to use the front-end! + if (member == null) + { + //log them out since they've been removed + FormsAuthentication.SignOut(); + model.IsLoggedIn = false; + return model; + } model.Name = member.UserName; model.Username = member.UserName; model.Email = member.Email;