Jump to content


Different FrontEnd based on user login


  • You cannot reply to this topic
11 replies to this topic

#1 TraXas

    Etomite Forum Newbie

  • Member
  • 10 posts

Posted 07 November 2007 - 01:33 PM

Hi all,
I've been setting up my first Etomite site and everything went well until my client requested to have specific pages in the frontend only visible for registered users. As far as I can see, this is not so easy to do with the existing snippets and before diving to much into custom development I wondered if there are already some easy validated solutions out there.
Thanks in advance.
Traxas

#2 cathode

    Loves Etomite Forums!

  • Staff
  • 648 posts
  • Gender:Male

Posted 07 November 2007 - 02:11 PM

This is doable in Etomite with no modification, it's just more complicated that many of the other simple functions. I'll post a step-by-step later today when I get a moment.

#3 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 07 November 2007 - 02:17 PM

This task is far easier than you might expect... Many sites are using permissions based display of resources... I have covered this issue several times before here in the forums... You need to start with either one of the authenticate_visitor or Login|Logout snippets... After that you can create a modified version of your menu snippet (I use authListMenu) to display menu items based on $etomite->checkPermissions()... This is only one way to do this and there are several other methods, but all rely on the visitor being authenticated... Check the tutorials section of my development website for more detailed information... I use the methods covered there to write entire web applications based on front end authentication...

#4 TraXas

    Etomite Forum Newbie

  • Member
  • 10 posts

Posted 07 November 2007 - 03:41 PM

Thanks Ralph,
I used the authenticate_visitor snippet and can login/ logout and acces (or not if not logged in) the parts of the site I put behind the authentication flags using roles and permissions. The only thing I can not get to work is the snippets to throw out links that are not valid when not loged in I tried building my own authListMenu and horiMenu. I used the following code for horiMenu since that seemed the easiest one:
$childrenOrig = $etomite->getActiveChildren($id); $menu = ""; 
// throw out all the not authenticated childeren
$counter = 0;
$children = Array();
foreach ($childrenOrig as $childItem)
{   
    if(
    ($childItem['authenticate'] && $etomite->checkPermissions($childItem['id'])) || !$childItem['authenticate'] )
	{
		$children[$counter] = $childItem;
		$counter++;
	}
}
I do have the flag authenticate on for some of the childeren, but $childItem['authenticate'] always is false.
I'm using version 0.6.1.4. Also could you provide me a link to your authListMenu snippet?
Is this the wrong way to test this? Any help is greatly appriciated
TraXas

#5 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 07 November 2007 - 06:13 PM

For your menu you only need a simple if clause to make things work... When you loop through the records pulled from the database just use something similar to the code below within your snippet... You don't need to query based on authenticate at all - that is all handled inside the parser within checkPermissions()...

// does this user have permissions to see this document and as a menu option?
// let's check the permissions for this document id
if($etomite->checkPermissions($row['id']))
{
  ...process this record into a menu item...
}

It's that simple... B)

#6 TraXas

    Etomite Forum Newbie

  • Member
  • 10 posts

Posted 07 November 2007 - 07:47 PM

I must be misunderstanding something here.
In my setup I've done the following:
doc 1 --> Flag Authenticate not set, no permissions set
doc 2 --> Flag Authenticate set, permissions set to members_only
user traxas is part of the member group

My intention is to show in the menu when nobody is loged on:
- doc 1
When user traxas is logged on
- doc 1
- doc 2
However when I use the code below, I get for no user no entries and for user traxas only doc 2

// does this user have permissions to see this document and as a menu option?
 // let's check the permissions for this document id
 if($etomite->checkPermissions($row['id']))
 {
   ...process this record into a menu item...
 }
I guess my understanding of this API-function is incorrect: I would expect that it would also return true if the document is visible for everyone.
That being said, I guess I'm overseeing something stupid here, but I have no clue what it is.
TraXas.

Edited by TraXas, 07 November 2007 - 07:49 PM.


#7 TraXas

    Etomite Forum Newbie

  • Member
  • 10 posts

Posted 08 November 2007 - 11:39 AM

Meanwhile I got it working.
The checkPermissions() function does not check if the flag authenticate is not set and returns FALSE in this case. so I went back to my original code, but the problem was that getActiveChildren() does not load by default the authenticate field. The fix:
$childrenOrig = $etomite->getActiveChildren($id, 'menuindex', 'ASC', 'id, pagetitle, description, parent, alias, longtitle, authenticate'); 
// throw out all the not authenticated childeren
foreach ($childrenOrig as $childItem)
{   
        if(($etomite->checkPermissions($childItem['id'])) || (!$childItem['authenticate'] ))
	{
		$children[] = $childItem;
	}
}
TraXas.

#8 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 08 November 2007 - 02:19 PM

View PostTraXas, on Nov 8 2007, 06:39 AM, said:

Meanwhile I got it working.
The checkPermissions() function does not check if the flag authenticate is not set and returns FALSE in this case. so I went back to my original code, but the problem was that getActiveChildren() does not load by default the authenticate field.
Ahhh... I forgot to mention that small detail... Sorry about that... I actually send authenticate in the field list so it can be tested... I just checked my authListMenu snippet and it uses the following code in the authentication check... If memory serves me correcly, the reasoning for the additional piece in my code accounts for whether or not visitor permissions are enabled in my configuration... This code should work whether visitor permissions are enabled or disabled...

if(($childItem['authenticate']
&& $etomite->checkPermissions($childItem['id']))
|| !$childItem['authenticate'])
{


#9 TraXas

    Etomite Forum Newbie

  • Member
  • 10 posts

Posted 09 November 2007 - 09:43 AM

View PostRalph, on Nov 8 2007, 03:19 PM, said:

Ahhh... I forgot to mention that small detail... Sorry about that... I actually send authenticate in the field list so it can be tested...
Nop, problem solved :) .
But would it not be better to have the
getActiveChilderen() call by default also returns the authenticate field ( Just a thought)
TraXas.

#10 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 09 November 2007 - 02:20 PM

View PostTraXas, on Nov 9 2007, 04:43 AM, said:

Nop, problem solved :) .
But would it not be better to have the
getActiveChilderen() call by default also returns the authenticate field ( Just a thought)
TraXas.
That could be added to the 0615 code base, I guess... I have already added the showinmenu flag so it kinda makes sense to have authenticate in the field list too...

#11 Opal

    Etomite Forum Newbie

  • Member
  • 23 posts

Posted 23 March 2009 - 01:33 AM

I'm have a hard time figuring out where I've gone wrong with this authentication mod. I know it's simple, but I'm stumped!
I've attached my version. Changes begin on line 156.
Right now I'm getting some interesting output results: 1, R, or 0. I can provide login details, if needed.

Can anyone give me a hand, please?

In ridiculous, I have authentication working in the ListChildorSibs snippet. Don't ask me how! :blink:

Attached Files



#12 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 31 March 2009 - 08:46 AM

Implementation for this here.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users