You are here

public function UserCredentials::execute in DRD Agent 8.3

Same name and namespace in other branches
  1. 4.0.x src/Agent/Action/UserCredentials.php \Drupal\drd_agent\Agent\Action\UserCredentials::execute()

Execute an action.

Return value

mixed The response of the action as an array which will be encrypted before returned to DRD.

Overrides Base::execute

File

src/Agent/Action/UserCredentials.php, line 16

Class

UserCredentials
Provides a 'UserCredentials' code.

Namespace

Drupal\drd_agent\Agent\Action

Code

public function execute() {
  $args = $this
    ->getArguments();

  /** @var \Drupal\user\Entity\User $account */
  $account = User::load($args['uid']);
  if (!$account) {
    $this->messenger
      ->addMessage('User does not exist.', 'error');
  }
  else {
    $this
      ->setUsername($account, $args);
    $this
      ->setPassword($account, $args);
    $this
      ->setStatus($account, $args);
    try {
      $account
        ->save();
    } catch (Exception $ex) {
      $this->messenger
        ->addMessage('Changing user credentials failed.', 'error');
    }
  }
  return [];
}