Example #1
0
 public function loadCurrent()
 {
     $f3 = \Base::instance();
     // Admins can masquerade as clients, so we need to load that
     $mask = $f3->get('SESSION.mask');
     if ($mask && \Helpers\User::validateUser($mask)) {
         $user = \Helpers\User::getUser($mask);
     } else {
         // No mask, try to load from session
         $id = $f3->get('SESSION.id');
         if ($id && \Helpers\User::validateUser($id)) {
             $user = \Helpers\User::getUser($id);
         }
     }
     if (isset($user)) {
         // User is logged in
         if ($user->suspended_time != null) {
             // User is suspended
             $f3->clear('SESSION.id');
             $f3->reroute('/auth/login');
         } else {
             // Valid, go
             // Set defaults
             $f3->set('user', $user->cast());
             $f3->set('user_obj', $user);
             $f3->set('user_org', \Helpers\User::getUserOrganisations($user->id));
             $f3->set('user_org_links', \Helpers\User::getUserOrganisationLinks($user->id));
             if ($user->exists('language') and $user->language) {
                 $f3->set('LANGUAGE', $user->language);
             }
             return true;
         }
     }
     // We'll never come here, but the IDE complains so here it is
     return true;
 }