public function SessionLimit::onSessionLimitBypass in Session Limit 2.x
Same name and namespace in other branches
- 8 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 209
Class
Namespace
Drupal\session_limit\ServicesCode
public function onSessionLimitBypass(SessionLimitBypassEvent $event) {
$admin_bypass_check = $this->configFactory
->get('session_limit.settings')
->get('session_limit_admin_inclusion');
$uid = $admin_bypass_check ? 1 : 2;
if ($this
->getCurrentUser()
->id() < $uid) {
// 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;
}
}