Exemple #1
0
 /**
  * Check for the user session
  *
  * @param  Application $application
  * @return void
  */
 public static function check(Application $application)
 {
     $sess = $application->getService('session');
     $action = $application->router()->getRouteMatch()->getAction();
     if (isset($sess->user) && isset($sess->user->sess_id) && !isset(Table\UserSessions::findById($sess->user->sess_id)->id)) {
         $user = new Model\User();
         $user->logout($sess);
         unset($sess->user);
         $sess->setRequestValue('expired', true);
         Response::redirect('/login');
         exit;
     } else {
         if (isset($sess->user) && ($action == 'login' || $action == 'forgot' || $action == 'verify')) {
             Response::redirect('/');
             exit;
         } else {
             if (!isset($sess->user) && $action != 'login' && $action != 'forgot' && $action != 'verify') {
                 Response::redirect('/login');
                 exit;
             }
         }
     }
 }
Exemple #2
0
 /**
  * Get count of user sessions
  *
  * @param  string $username
  * @return int
  */
 public function getCount($username = null)
 {
     if (null !== $username) {
         $sql = Table\UserSessions::sql();
         $sql->select(['id' => DB_PREFIX . 'user_sessions.id', 'username' => DB_PREFIX . 'users.username'])->join(DB_PREFIX . 'users', [DB_PREFIX . 'users.id' => DB_PREFIX . 'user_sessions.user_id']);
         $sql->select()->where('username LIKE :username');
         $params = ['username' => $username . '%'];
         return Table\UserSessions::execute((string) $sql, $params, Table\UserSessions::ROW_AS_ARRAY)->count();
     } else {
         return Table\UserSessions::findAll(null, Table\UserSessions::ROW_AS_ARRAY)->count();
     }
 }