Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. UserRegistrationResource.php

function 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 99

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.
    if ($this->userSettings
        ->get('register') == UserInterface::REGISTER_VISITORS) {
        $account->activate();
    }
    else {
        $account->block();
    }
    // Generate password if email verification required.
    if ($this->userSettings
        ->get('verify_mail')) {
        $account->setPassword($this->passwordGenerator
            ->generate());
    }
    $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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal