You are here

public function CasTestSubscriber::onPreRegister in CAS 2.x

Same name and namespace in other branches
  1. 8 tests/modules/cas_test/src/CasTestSubscriber.php \Drupal\cas_test\CasTestSubscriber::onPreRegister()

Change the username of the user being registered.

Parameters

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

File

tests/modules/cas_test/src/CasTestSubscriber.php, line 30

Class

CasTestSubscriber
Subscribes to pre-login and pre-register events.

Namespace

Drupal\cas_test

Code

public function onPreRegister(CasPreRegisterEvent $event) {

  // Add a prefix of "testing_" to the CAS username.
  $username = $event
    ->getDrupalUsername();
  $new_username = 'testing_' . $username;
  $event
    ->setDrupalUsername($new_username);
  $flag = \Drupal::state()
    ->get('cas_test.flag');
  if ($flag === 'cancel register without message') {
    $event
      ->cancelAutomaticRegistration();
  }
  elseif ($flag === 'cancel register with message') {
    $event
      ->cancelAutomaticRegistration('Cancelled with a custom message.');
  }
}