You are here

class IpLoginSubscriber in IP Login 4.x

IP Login subscriber.

Hierarchy

  • class \Drupal\ip_login\EventSubscriber\IpLoginSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of IpLoginSubscriber

1 string reference to 'IpLoginSubscriber'
ip_login.services.yml in ./ip_login.services.yml
ip_login.services.yml
1 service uses IpLoginSubscriber
ip_login.subscriber in ./ip_login.services.yml
Drupal\ip_login\EventSubscriber\IpLoginSubscriber

File

src/EventSubscriber/IpLoginSubscriber.php, line 13

Namespace

Drupal\ip_login\EventSubscriber
View source
class IpLoginSubscriber implements EventSubscriberInterface {

  /**
   * Clears various IP Login cookies if needed.
   *
   * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
   *   The response event.
   */
  public function onKernelResponse(FilterResponseEvent $event) {
    if (!$event
      ->isMasterRequest()) {
      return;
    }
    $response = $event
      ->getResponse();
    if ($event
      ->getRequest()->attributes
      ->get('ip_login_user_login')) {
      $response->headers
        ->setCookie(new Cookie('ipLoginAttempted', '', 1));
      $response->headers
        ->setCookie(new Cookie('ipLoginAsDifferentUser', '', 1));
    }
    $can_login_as_another_user = $event
      ->getRequest()->attributes
      ->get('ip_login_can_login_as_another_user');
    if ($can_login_as_another_user !== NULL) {
      $response->headers
        ->setCookie(new Cookie('ipLoginAsDifferentUser', $can_login_as_another_user));
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[KernelEvents::RESPONSE][] = [
      'onKernelResponse',
      0,
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
IpLoginSubscriber::getSubscribedEvents public static function
IpLoginSubscriber::onKernelResponse public function Clears various IP Login cookies if needed.