Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • trfletch 598 posts 604 karma points
    Aug 07, 2009 @ 10:58
    trfletch
    0

    Restricting content to specific members

    Hi,

    I have got content on my website that I want to restrict to certain members, currently the content is restricted to only logged in users but I want to be able to restrict it further so that it is only specific logged in users (one's that have subscribed to the content). I am using a custom membership provider and currently have the following code in an XSLT file. Is there an Umbraco command that I can use to restrict the content to specific users by checking the logged on users role or somthing similar?

  • Chris Koiak 700 posts 2626 karma points
    Aug 07, 2009 @ 11:16
    Chris Koiak
    1

    Hi,

    You need to create different member groups for the different roles you require.

    You can check access to a page using

    <ul>
        <xsl:for-each select="$source/node [
                string(data [@alias='umbracoNaviHide']) != '1'
                and (umbraco.library:IsProtected(@id, @path) = false()
                    or umbraco.library:HasAccess(@id, @path) = true())
                ]">
            <li>
                <a href="{umbraco.library:NiceUrl(@id)}">
                    <xsl:value-of select="@nodeName"/>
                </a>
            </li>
        </xsl:for-each>
    </ul>

    (taken from http://forum.umbraco.org/yaf_postst4609_UmbracoLibraryHasAccess-returns-false-on-pages-that-arent-protected.aspx)

    You need to check both Protected and HasAccess.

    I assume this works with custom membership providers, it definately works well with standard umbraco members.

    You can check out my clientarea project for an example of a similar member setup (shameless plug!).

    Chris

  • trfletch 598 posts 604 karma points
    Aug 07, 2009 @ 17:58
    trfletch
    0

    Hi Chris,

    Thanks for the response, I will not be using groups because I am using a custom membership provider therefore does anyone know if I can check the members role from my custom membership provider to determine which parts they can see?

  • Chris Koiak 700 posts 2626 karma points
    Aug 09, 2009 @ 08:55
    Chris Koiak
    0

    Have you tried setting the 'pubilc access' for a document and then checking the return values for the extension methods above?

    If it doesn't work I'd be a bit disappointed as I thought that was (one of) the benefits of the custom member providers functionality.

    If not you'll need to write your own xslt extension. The umbraco 'Access' class has a number of static methods you can use to determine the roles required to access page. You should then compare those with the IsInRole method in the custom membership provider.

    If anyone has more experience of this please chip in.

  • trfletch 598 posts 604 karma points
    Aug 17, 2009 @ 12:39
    trfletch
    0

    Hi Chris thanks for the response, I have been off for a week so have not replied. I don't really understand what you mean, surely setting the public access will not work because I want to restrict just one part of the page not the whole page.

    Does anyone know if it is possible to set a custom property for a member and check that to see if they can view the content, for example the member could have a customer property called "subscriber" and if the value of that property is "yes" they can see member content but if it is "no" they cannot. The XSLT I currently have is as follows, hopefully someone knows what I can add to check a custom property for the user?

     

    <xsl:choose>
     <xsl:when test="umbraco.library:IsLoggedOn() = 1">
     <div id="nonmemberstext">
     <xsl:value-of select="$currentPage/data [@alias = 'nonmemberstext']" disable-output-escaping="yes"/>
     </div>
     <div id="memberstext">
     <xsl:value-of select="$currentPage/data [@alias = 'memberstext']" disable-output-escaping="yes"/>
     <br/>
     </div>
     </xsl:when>
     <xsl:otherwise>
     <div id="nonmemberstext">
     <xsl:value-of select="$currentPage/data [@alias = 'nonmemberstext']" disable-output-escaping="yes"/>
     </div>
     <p>To view full article please login</p>
     </xsl:otherwise>
    </xsl:choose>

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 17, 2009 @ 12:52
    Dirk De Grave
    0

    Hi trfletch,

    umbraco.library:GetCurrentMember()

    returns all member info, including custom properties you've defined, so you use that one in xslt

     

    Cheers,

    /Dirk

  • trfletch 598 posts 604 karma points
    Aug 17, 2009 @ 13:08
    trfletch
    0

    Hi Dirk,

    Thanks for the response, sorry if I'm being stupid but how would I use that to just show member content to members that have a custom property called "subscriber" with the value of "yes". I was hoping that I could modify my XSLT something like this (see the part in bold):

    <xsl:choose>
     <xsl:when test="umbraco.library:IsLoggedOn() = 1" and "umbraco.library:GetCurrentMember()/data[@alias = 'subscriber'] ='1'" >
     <div id="nonmemberstext">
     <xsl:value-of select="$currentPage/data [@alias = 'nonmemberstext']" disable-output-escaping="yes"/>
     </div>
     <div id="memberstext">
     <xsl:value-of select="$currentPage/data [@alias = 'memberstext']" disable-output-escaping="yes"/>
     <br/>
     </div>
     </xsl:when>
     <xsl:otherwise>
     <div id="nonmemberstext">
     <xsl:value-of select="$currentPage/data [@alias = 'nonmemberstext']" disable-output-escaping="yes"/>
     </div>
     <p>To view full article please login</p>
     </xsl:otherwise>
    </xsl:choose>

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 17, 2009 @ 13:30
    Dirk De Grave
    0

    Hi 

    <xsl:when test="umbraco.library:IsLoggedOn() = 1 and umbraco.library:GetCurrentMember()/data[@alias = 'subscriber'] ='1'" >

    Removed double quotes from  '1" and "umbraco'

     

    Cheers,

    /Dirk

  • almir 11 posts 26 karma points
    Aug 17, 2009 @ 17:19
    almir
    0

    Has anyone manages to solve this?

  • trfletch 598 posts 604 karma points
    Aug 17, 2009 @ 21:19
    trfletch
    0

    I haven't had chance to give this a try yet but should that work ok? I'm quite shocked at the thought that I managed to work out what code was needed plus or minus a few quotes.

Please Sign in or register to post replies

Write your reply to:

Draft