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?
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?
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.
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?
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):
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.
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?
Hi,
You need to create different member groups for the different roles you require.
You can check access to a page using
(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
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?
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.
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?
Hi trfletch,
returns all member info, including custom properties you've defined, so you use that one in xslt
Cheers,
/Dirk
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>
Hi
Removed double quotes from '1" and "umbraco'
Cheers,
/Dirk
Has anyone manages to solve this?
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.
is working on a reply...