/// <summary> /// Ensures that access to current node is permitted. /// </summary> /// <remarks>Redirecting to a different site root and/or culture will not pick the new site root nor the new culture.</remarks> private void EnsurePublishedContentAccess() { const string tracePrefix = "EnsurePublishedContentAccess: "; if (_pcr.PublishedContent == null) { throw new InvalidOperationException("There is no PublishedContent."); } var path = _pcr.PublishedContent.Path; var publicAccessAttempt = Services.PublicAccessService.IsProtected(path); if (publicAccessAttempt) { ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Page is protected, check for access", () => tracePrefix); var membershipHelper = new MembershipHelper(_routingContext.UmbracoContext); if (membershipHelper.IsLoggedIn() == false) { ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Not logged in, redirect to login page", () => tracePrefix); var loginPageId = publicAccessAttempt.Result.LoginNodeId; if (loginPageId != _pcr.PublishedContent.Id) { _pcr.PublishedContent = _routingContext.UmbracoContext.ContentCache.GetById(loginPageId); } } else if (Services.PublicAccessService.HasAccess(_pcr.PublishedContent.Id, Services.ContentService, _pcr.GetRolesForLogin(membershipHelper.CurrentUserName)) == false) { ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Current member has not access, redirect to error page", () => tracePrefix); var errorPageId = publicAccessAttempt.Result.NoAccessNodeId; if (errorPageId != _pcr.PublishedContent.Id) { _pcr.PublishedContent = _routingContext.UmbracoContext.ContentCache.GetById(errorPageId); } } else { ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Current member has access", () => tracePrefix); } } else { ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Page is not protected", () => tracePrefix); } }
/// <summary> /// Ensures that access to current node is permitted. /// </summary> /// <remarks>Redirecting to a different site root and/or culture will not pick the new site root nor the new culture.</remarks> private void EnsurePublishedContentAccess() { const string tracePrefix = "EnsurePublishedContentAccess: "; if (_pcr.PublishedContent == null) { throw new InvalidOperationException("There is no PublishedContent."); } var path = _pcr.PublishedContent.Path; var publicAccessAttempt = Services.PublicAccessService.IsProtected(path); if (publicAccessAttempt) { ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Page is protected, check for access", () => tracePrefix); var membershipHelper = new MembershipHelper(_routingContext.UmbracoContext); if (membershipHelper.IsLoggedIn() == false) { ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Not logged in, redirect to login page", () => tracePrefix); var loginPageId = publicAccessAttempt.Result.LoginNodeId; if (loginPageId != _pcr.PublishedContent.Id) { _pcr.PublishedContent = _routingContext.UmbracoContext.ContentCache.GetById(loginPageId); } } else if (Services.PublicAccessService.HasAccess(_pcr.PublishedContent.Id, Services.ContentService, _pcr.GetRolesForLogin(membershipHelper.CurrentUserName)) == false) { ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Current member has not access, redirect to error page", () => tracePrefix); var errorPageId = publicAccessAttempt.Result.NoAccessNodeId; if (errorPageId != _pcr.PublishedContent.Id) { _pcr.PublishedContent = _routingContext.UmbracoContext.ContentCache.GetById(errorPageId); } } else { if (membershipHelper.IsUmbracoMembershipProviderActive()) { // grab the current member var member = membershipHelper.GetCurrentMember(); // if the member has the "approved" and/or "locked out" properties, make sure they're correctly set before allowing access var memberIsActive = true; if (member != null) { if (member.HasProperty(Constants.Conventions.Member.IsApproved) == false) { memberIsActive = member.GetPropertyValue <bool>(Constants.Conventions.Member.IsApproved); } if (member.HasProperty(Constants.Conventions.Member.IsLockedOut) == false) { memberIsActive = member.GetPropertyValue <bool>(Constants.Conventions.Member.IsLockedOut) == false; } } if (memberIsActive == false) { ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Current member is either unapproved or locked out, redirect to error page", () => tracePrefix); var errorPageId = publicAccessAttempt.Result.NoAccessNodeId; if (errorPageId != _pcr.PublishedContent.Id) { _pcr.PublishedContent = _routingContext.UmbracoContext.ContentCache.GetById(errorPageId); } } else { ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Current member has access", () => tracePrefix); } } else { ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Current custom MembershipProvider member has access", () => tracePrefix); } } } else { ProfilingLogger.Logger.Debug <PublishedContentRequestEngine>("{0}Page is not protected", () => tracePrefix); } }