Example #1
0
 public function post()
 {
     $f3 = \Base::instance();
     $userId = User::getUserId($f3->get("POST.username"));
     if ($userId) {
         if (User::verifyUserPassword($userId, $f3->get("POST.password"))) {
             $user = User::getUser($userId);
             // Check if the user is suspended
             if ($user->suspended_time != null) {
                 $f3->set('error', sprintf('Your account is suspended since %s, check your email.', $user->suspended_time));
             } else {
                 // GO GO GO !
                 $f3->set('SESSION.id', $user->id);
                 $f3->reroute("/dashboard");
                 return;
             }
         } else {
             $f3->set('error', 'Wrong username/password combination');
         }
     } else {
         $f3->set('error', 'Wrong username/password combination');
     }
     $f3->set('css', array('/static/css/auth.css'));
     $f3->set('target', 'auth/login.html');
     $this->_render('base.html');
 }
Example #2
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;
 }