You are here

public function CasUserInteractionTestSubscriber::onPreUserLoadRedirect in CAS 8

Same name and namespace in other branches
  1. 2.x tests/modules/cas_user_interaction_test/src/CasUserInteractionTestSubscriber.php \Drupal\cas_user_interaction_test\CasUserInteractionTestSubscriber::onPreUserLoadRedirect()

Redirects to a form that asks user to accept the site's 'Legal Notice'.

Parameters

\Drupal\cas\Event\CasPreUserLoadRedirectEvent $event: The event.

File

tests/modules/cas_user_interaction_test/src/CasUserInteractionTestSubscriber.php, line 31

Class

CasUserInteractionTestSubscriber
Class CasTestSubscriber.

Namespace

Drupal\cas_user_interaction_test

Code

public function onPreUserLoadRedirect(CasPreUserLoadRedirectEvent $event) {
  $is_legal_notice_changed = \Drupal::state()
    ->get('cas_user_interaction_test.changed', FALSE);
  $local_account = \Drupal::service('externalauth.externalauth')
    ->load($event
    ->getPropertyBag()
    ->getUsername(), 'cas');

  // Add a redirect only if a local account exists (i.e. it's a login
  // operation) and the site's 'Legal Notice' has changed.
  if ($local_account && $is_legal_notice_changed) {

    /** @var \Drupal\Core\TempStore\PrivateTempStore $tempstore */
    $tempstore = \Drupal::service('tempstore.private')
      ->get('cas_user_interaction_test');
    $tempstore
      ->set('ticket', $event
      ->getTicket());
    $tempstore
      ->set('property_bag', $event
      ->getPropertyBag());
    $event
      ->setRedirectResponse(new RedirectResponse(Url::fromRoute('cas_user_interaction_test.form')
      ->toString()));
  }
}