You are here

public function CasUserManager::register in CAS 2.x

Same name and namespace in other branches
  1. 8 src/Service/CasUserManager.php \Drupal\cas\Service\CasUserManager::register()

Register a local Drupal user given a CAS username.

Parameters

string $authname: The CAS username.

string $local_username: The local Drupal username to be created.

array $property_values: (optional) Property values to assign to the user on registration.

Return value

\Drupal\user\UserInterface The user entity of the newly registered user.

Throws

\Drupal\cas\Exception\CasLoginException When the user account could not be registered.

1 call to CasUserManager::register()
CasUserManager::login in src/Service/CasUserManager.php
Attempts to log the user in to the Drupal site.

File

src/Service/CasUserManager.php, line 150

Class

CasUserManager
Provides the 'cas.user_manager' service default implementation.

Namespace

Drupal\cas\Service

Code

public function register($authname, $local_username, array $property_values = []) {
  $property_values['name'] = $local_username;
  $property_values['pass'] = $this
    ->randomPassword();
  try {
    $user = $this->externalAuth
      ->register($authname, $this->provider, $property_values);
  } catch (ExternalAuthRegisterException $e) {
    throw new CasLoginException($e
      ->getMessage(), CasLoginException::USERNAME_ALREADY_EXISTS);
  }
  return $user;
}