Page 1 of 1

Default table after Login

PostPosted: Mon Jun 23, 2008 8:45 am
by meta
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

PostPosted: Mon Jun 23, 2008 9:05 am
by shannah
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

PostPosted: Mon Jun 23, 2008 9:06 am
by shannah
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

PostPosted: Tue Jun 24, 2008 5:42 am
by meta
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

PostPosted: Tue Jun 24, 2008 9:57 am
by shannah
Code: Select all
function isLoggedIn(){
    $auth =& Dataface_AuthenticationTool::getInstance();
    return $auth->isLoggedIn();
}


PostPosted: Tue Jun 24, 2008 12:56 pm
by meta
Thank you very much Steve. It works perfect :D

Markus

About isLoggedIn() and getUserRole()

PostPosted: Sat Jun 20, 2009 1:57 pm
by ulisespm
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

Re: Default table after Login

PostPosted: Thu Mar 29, 2012 6:01 am
by jimr451
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