You are here

public function CasCommands::setCasUsername in CAS 8

Same name and namespace in other branches
  1. 2.x src/Commands/CasCommands.php \Drupal\cas\Commands\CasCommands::setCasUsername()

Sets CAS username for an existing Drupal user.

@usage cas:set-cas-username foo bar Assigns the CAS username of "bar" to the Drupal user with name "foo"

@command cas:set-cas-username

Parameters

string $drupalUsername: The drupal user name of the user to modify.

string $casUsername: The CAS username to assign to the user.

File

src/Commands/CasCommands.php, line 25

Class

CasCommands
Drush command file for CAS commands.

Namespace

Drupal\cas\Commands

Code

public function setCasUsername($drupalUsername, $casUsername) {
  $account = user_load_by_name($drupalUsername);
  if ($account) {
    $casUserManager = \Drupal::service('cas.user_manager');
    $casUserManager
      ->setCasUsernameForAccount($account, $casUsername);
    $this->logger
      ->success(dt('Assigned CAS username "!casUsername" to user "!drupalUsername"', [
      '!casUsername' => $casUsername,
      '!drupalUsername' => $drupalUsername,
    ]));
  }
  else {
    $this->logger
      ->error(dt('Unable to load user: !user', [
      '!user' => $drupalUsername,
    ]));
  }
}