Page 1 of 1

Showing a different page to user depending on group [SOLVED]

Posted: Mon Feb 07, 2011 6:20 pm
by Fraserm
Hi guys,

I have a situation in which I want to add groups x and y, check to see if a user is a member of any of those groups and if they are, direct them to a different page depending on which group they are a member of, i.e. Group X will be redirected to Page X, Group Y to Page Y and so on.

I realise that I could do that with several {if} statements in my template and {redirect}s but I really need it to continue working if I add more groups without having to edit the template every time to add new statements.

What i've done so far:
1. Created two users "User 1" and "User 2".
2. Created two groups "Group X" and "Group Y".
3. Assigned "User 1" to "Group X" and "User 2" to "Group Y".
4. Created two new pages, one for each user to see when they're logged in.
5. Added an extra attribute value to each of the pages, "Group X" and "Group Y".
6. Added the following code to the template i'm using for protected pages:

Code: Select all

{if $ccuser->loggedin() && $ccuser->memberof($content_obj->GetPropertyValue('extra1'))}
{redirect_page page='($content_obj->GetPropertyValue('extra1'))'}
{content}
{else}
Not authorized
{/if}
What happens is that the user is always shown the "Note Authorized" message, regardless of group membership.

I guess i'm on the wrong track here. Could someone give me some guidance please?

Re: Showing a different page to a user depending on group

Posted: Mon Feb 07, 2011 7:58 pm
by Dr.CSS
Maybe make sure extra1 and alias of page are the same?...

Re: Showing a different page to a user depending on group

Posted: Mon Feb 07, 2011 8:13 pm
by Fraserm
Hi Dr.CSS,

Thank you for your response. That is the case though. The page alias and the extra attribute have the same value and yet it the page always displays 'Not Authorized' regardless.

Do you see any problems with my approach or my syntax?

Many thanks.

Edit: I should add that the group name is also the same. Group name, page alias and extra1 all share the same value.

Re: Showing a different page to a user depending on group

Posted: Mon Feb 07, 2011 8:16 pm
by Dr.CSS
Maybe you need to capture the value out side of the memberof call then put the assigned value in the memberof call...

Re: Showing a different page to a user depending on group

Posted: Mon Feb 07, 2011 10:55 pm
by jmcgin51
Fraserm wrote:Hi guys,

Code: Select all

{if $ccuser->loggedin() && $ccuser->memberof($content_obj->GetPropertyValue('extra1'))}
{redirect_page page='($content_obj->GetPropertyValue('extra1'))'}
{content}
{else}
Not authorized
{/if}
Try {page_attr key='extra1'} instead of ($content_obj->GetPropertyValue('extra1')

http://forum.cmsmadesimple.org/viewtopi ... =4&t=46284

Re: Showing a different page to a user depending on group

Posted: Mon Feb 07, 2011 11:13 pm
by Fraserm
Hi all,

I found an old post that Calguy wrote following a question from a user who asked something very similar to me (I did search earlier, I promise).

His suggestion was to use GCBs (GCB name the same as the login name), one for each Group, with the following code in the template:

Code: Select all

{if $ccuser->LoggedIn()}
{global_content name=$customcontent_loginname}
{/if}
You need to remember to mark your page as non-cachable for this to work, but work it does. In addition to that code I added the stuff needed to display the login form if the user isn't logged in etc:

Code: Select all

{if $ccuser->LoggedIn()}
{cms_module module=FrontEndUsers nocaptcha="1" form="logout" returnto="home"}
{else}
{cms_module module=FrontEndUsers nocaptcha="1" form="login"}
{/if}

{if $ccuser->LoggedIn()}
{global_content name=$customcontent_loginname}
{else}
<span class="normal_text">You're not currently logged in. Please login to see your content.</span>
{/if}

{/if}



I think this will do just find for me this time round, so i'll mark the original post as solved.