Setting a default table based on the user logged in

A place to discuss development of the Xataface core.

Setting a default table based on the user logged in

Postby rlevin » Tue Apr 26, 2011 7:40 am

Using the beforeHandleRequest() function works but only when each user has one table. If I were to click on TableB, TableA would show instead since beforeHandleRequest() is called on every request. How should I approach this problem? My tables are hidden from user to user using the getNavItem() method. Ive also tried the after_action_login() method but that didn't work.

Here's what I have at the moment

Code: Select all
function after_action_login()
    {
      $auth =& Dataface_AuthenticationTool::getInstance();
      $user =& $auth->getLoggedInUser(); 
      $app = Dataface_Application::getInstance();
      $query =& $app->getQuery();
      switch($user->val('role'))
      {
         case 'ADMIN':
            $query['-table'] = 'TableA';
            break;
         case 'UserA':
            $query['-table'] = 'TableA';
            break;
         case 'UserB':
            $query['-table'] = 'TableB';
            break;
      }      
    }
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: Setting a default table based on the user logged in

Postby rlevin » Tue Apr 26, 2011 8:29 am

Here's something else I tried

Code: Select all
function isLoggedIn()
      {
      $auth =& Dataface_AuthenticationTool::getInstance();
    $user =& $auth->getLoggedInUser();
    if(isset($user)) return true;
    return false;
      }
     
     function beforeHandleRequest(){
    if (!isset($_SESSION['loggedInAlready']) and isLoggedIn() ){
        $_SESSION['loggedInAlready'] = true;
         $auth =& Dataface_AuthenticationTool::getInstance();
           $user =& $auth->getLoggedInUser();
         switch ($user->val('role')){
            case 'ADMIN':
                  $url= 'http://www........index.php?-table=TableA';
                  break;
            case 'UserA':
               $url = 'http://www.......index.php?-table=TableA';
               break;
            case 'UserB':
               $url = 'http://www........index.php?-table=TableB';
                 break;
        }
        header('Location: '.$url);
        exit;
    }
}



This doesn't work either.
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: Setting a default table based on the user logged in

Postby shannah » Tue Apr 26, 2011 2:00 pm

You're barking up the wrong tree by adding extra checks to see if they are logged in. The key thing to focus on when you implement the beforeHandleRequest method is that '-action' parameter.

Look at the wiki page for beforeHandleRequest for some examples on how to do this safely.
http://www.xataface.com/wiki/beforeHandleRequest
-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Developers

Who is online

Users browsing this forum: No registered users and 1 guest

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