You are here

public function UserRegistrationResource::post in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/src/Plugin/rest/resource/UserRegistrationResource.php \Drupal\user\Plugin\rest\resource\UserRegistrationResource::post()

Responds to user registration POST request.

Parameters

\Drupal\user\UserInterface $account: The user account entity.

Return value

\Drupal\rest\ModifiedResourceResponse The HTTP response object.

Throws

\Symfony\Component\HttpKernel\Exception\BadRequestHttpException

\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException

File

core/modules/user/src/Plugin/rest/resource/UserRegistrationResource.php, line 100

Class

UserRegistrationResource
Represents user registration as a resource.

Namespace

Drupal\user\Plugin\rest\resource

Code

public function post(UserInterface $account = NULL) {
  $this
    ->ensureAccountCanRegister($account);

  // Only activate new users if visitors are allowed to register and no email
  // verification required.
  if ($this->userSettings
    ->get('register') == UserInterface::REGISTER_VISITORS && !$this->userSettings
    ->get('verify_mail')) {
    $account
      ->activate();
  }
  else {
    $account
      ->block();
  }
  $this
    ->checkEditFieldAccess($account);

  // Make sure that the user entity is valid (email and name are valid).
  $this
    ->validate($account);

  // Create the account.
  $account
    ->save();
  $this
    ->sendEmailNotifications($account);
  return new ModifiedResourceResponse($account, 200);
}