You are here

public function SessionLimit::onSessionLimitBypass in Session Limit 8

Same name and namespace in other branches
  1. 2.x src/Services/SessionLimit.php \Drupal\session_limit\Services\SessionLimit::onSessionLimitBypass()

Event listener, on check for session check bypass.

Parameters

SessionLimitBypassEvent $event:

File

src/Services/SessionLimit.php, line 197

Class

SessionLimit

Namespace

Drupal\session_limit\Services

Code

public function onSessionLimitBypass(SessionLimitBypassEvent $event) {
  if ($this
    ->getCurrentUser()
    ->id() < 2) {

    // User 1 and anonymous don't get session checked.
    $event
      ->setBypass(TRUE);
    return;
  }
  if ($this
    ->getMasqueradeIgnore() && \Drupal::service('masquerade')
    ->isMasquerading()) {

    // Masquerading sessions do not count.
    $event
      ->setBypass(TRUE);
    return;
  }

  // @todo accessing the $_SESSION super global is probably bad.
  if (isset($_SESSION['session_limit'])) {

    // Already checked people do not get session checked.
    $event
      ->setBypass(TRUE);
    return;
  }
  $route = $this
    ->getRouteMatch();
  $current_path = $route
    ->getRouteObject()
    ->getPath();
  $bypass_paths = [
    '/session-limit',
    '/user/logout',
  ];
  if (in_array($current_path, $bypass_paths)) {

    // Don't session check on these routes.
    $event
      ->setBypass(TRUE);
    return;
  }
}