Setting a default table based on the user logged in

Archived from the Xataface Developers forum.

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 — 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.


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