Default table after Login

A place for users and developers of the Xataface to discuss and receive support.

Default table after Login

Postby 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
meta
 
Posts: 30
Joined: Mon Nov 12, 2007 8:30 am
Location: Berlin, Germany

Postby 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
Last edited by shannah on Mon Jun 23, 2008 9:07 am, edited 1 time in total.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby 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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby 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
meta
 
Posts: 30
Joined: Mon Nov 12, 2007 8:30 am
Location: Berlin, Germany

Postby shannah » Tue Jun 24, 2008 9:57 am

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

shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby meta » Tue Jun 24, 2008 12:56 pm

Thank you very much Steve. It works perfect :D

Markus
meta
 
Posts: 30
Joined: Mon Nov 12, 2007 8:30 am
Location: Berlin, Germany

About isLoggedIn() and getUserRole()

Postby 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
Best Regards
U.
ulisespm
 
Posts: 8
Joined: Fri Jun 19, 2009 1:59 pm
Location: Puebla

Re: Default table after Login

Postby 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
Jim Roberts
Roberts WebForge, Inc.
http://www.robertswebforge.com
jimr451
 
Posts: 20
Joined: Mon Jun 27, 2011 1:46 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 11 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved