Default table after Login

Archived from the Xataface Users forum.

meta — Mon Jun 23, 2008 8:45 am

Hi Steve, hi all,

Is there another possibility to have a default table after a user has logged in than changing the order of tables in conf.ini [_tables] ?

An example: I have 3 users, READ ONLY, EDIT and ADMIN.

I have 3 tables lets say table1, table2, table3.

Now it is like that all users after login start with table1 as this is the first listed in conf.ini [_tables].

What do I have to do to reach the following:

When the READ ONLY user logs in he should be directed to table1

When the EDIT user logs in he should be directed to table2

When the ADMIN user logs in he should be directed to table3

ADMIN should have access to all tables

EDIT should have access to tables 2 and 3

READ ONLY should have access only to table1

Thank you

Markus


shannah — Mon Jun 23, 2008 9:05 am

You can do this with sessions quite easily and the beforeHandleRequest() method.

Have a session variable to track whether the user has “logged in” yet.

e.g.

Code: Select all
function beforeHandleRequest(){     if (!isset($_SESSION['loggedInAlready']) and isLoggedIn() ){         $_SESSION['loggedInAlready'] = true;         switch (getUserRole()){             case 'ADMIN': $url= '...'; break;             case 'READ ONLY': $url = '...'; break;             case 'EDIT': $url = '...'; break;             default: $url = '...';         }         header('Location: '.$url);         exit;     } }

This assumes that you have defined functions isLoggedIn() and getUserRole() that do the obvious things.

Note* This code could also be placed inside the getPreferences() method of your application delegate class.

-Steve


shannah — Mon Jun 23, 2008 9:06 am

ADMIN should have access to all tables
EDIT should have access to tables 2 and 3
READ ONLY should have access only to table1

This can be done quite easily with permissions.

-Steve


meta — Tue Jun 24, 2008 5:42 am

shannah wrote:You can do this with sessions quite easily and the beforeHandleRequest() method.

Have a session variable to track whether the user has “logged in” yet.

e.g.

Code: Select all
function beforeHandleRequest(){     if (!isset($_SESSION['loggedInAlready']) and isLoggedIn() ){         $_SESSION['loggedInAlready'] = true;         switch (getUserRole()){             case 'ADMIN': $url= '...'; break;             case 'READ ONLY': $url = '...'; break;             case 'EDIT': $url = '...'; break;             default: $url = '...';         }         header('Location: '.$url);         exit;     } }

This assumes that you have defined functions isLoggedIn() and getUserRole() that do the obvious things.

Note* This code could also be placed inside the getPreferences() method of your application delegate class.

-Steve

Thank you Steve.

Can you give me an example for an isLoggedIn() function?

Markus


shannah — Tue Jun 24, 2008 9:57 am

Code: Select all
function isLoggedIn(){     $auth =& Dataface_AuthenticationTool::getInstance();     return $auth->isLoggedIn(); }

meta — Tue Jun 24, 2008 12:56 pm

Thank you very much Steve. It works perfect

Markus


ulisespm — Sat Jun 20, 2009 1:57 pm

Hi Steve, hi All,

Related to this topic. Where may I define the isLoggedIn() and the getUserRole() functions?

Moreover, which is the getUserRole() code? Should you give me an example?

Thanks in advance


jimr451 — Thu Mar 29, 2012 6:01 am

I also figured out I could do this:

( In the ApplicationDelegate.php, function beforeHandleRequest() { )

When I determine the role of the user, I can switch their table like so:

Code: Select all
if ( $query['-table'] == 'events') {               $query['-table'] = 'articles';              }

So the default table is “events”, but this user can’t see that table - so they get a “Permission Denied” as soon as they login. So I just check to see if they are trying to view “events”, and switch the table to “articles”, which they can see. Seems to work fine.

-Jim