public function AutologoutSubscriber::onRequest in Automated Logout 8
Check for autologout JS.
Parameters
\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: The request event.
File
- src/
EventSubscriber/ AutologoutSubscriber.php, line 93
Class
- AutologoutSubscriber
- Defines autologout Subscriber.
Namespace
Drupal\autologout\EventSubscriberCode
public function onRequest(GetResponseEvent $event) {
$autologout_manager = $this->autoLogoutManager;
$uid = $this->currentUser
->id();
if ($uid == 0) {
$autologout_timeout = $this->requestStack
->getCurrentRequest()->query
->get('autologout_timeout');
$post = $this->requestStack
->getCurrentRequest()->request
->all();
if (!empty($autologout_timeout) && $autologout_timeout == 1 && empty($post)) {
$autologout_manager
->inactivityMessage();
}
return;
}
if ($this->autoLogoutManager
->preventJs()) {
return;
}
$now = $this->time
->getRequestTime();
// Check if anything wants to be refresh only. This URL would include the
// javascript but will keep the login alive whilst that page is opened.
$refresh_only = $autologout_manager
->refreshOnly();
$timeout = $autologout_manager
->getUserTimeout();
$timeout_padding = $this->config
->get('autologout.settings')
->get('padding');
$is_altlogout = strpos($event
->getRequest()
->getRequestUri(), '/autologout_alt_logout') !== FALSE;
// We need a backup plan if JS is disabled.
if (!$is_altlogout && !$refresh_only && isset($_SESSION['autologout_last'])) {
// If time since last access is > timeout + padding, log them out.
$diff = $now - $_SESSION['autologout_last'];
if ($diff >= $timeout + (int) $timeout_padding) {
$autologout_manager
->logout();
// User has changed so force Drupal to remake decisions based on user.
global $theme, $theme_key;
drupal_static_reset();
$theme = NULL;
$theme_key = NULL;
$this->theme
->getActiveTheme();
$autologout_manager
->inactivityMessage();
}
else {
$_SESSION['autologout_last'] = $now;
}
}
else {
$_SESSION['autologout_last'] = $now;
}
}