diff -u b/core/modules/user/config/install/user.settings.yml b/core/modules/user/config/install/user.settings.yml --- b/core/modules/user/config/install/user.settings.yml +++ b/core/modules/user/config/install/user.settings.yml @@ -1,6 +1,5 @@ anonymous: Anonymous verify_mail: true -password_register: false notify: cancel_confirm: true password_reset: true @@ -10,6 +9,7 @@ register_admin_created: true register_no_approval_required: true register_pending_approval: true + register_password_set: false register: visitors cancel_method: user_cancel_block password_reset_timeout: 86400 diff -u b/core/modules/user/config/schema/user.schema.yml b/core/modules/user/config/schema/user.schema.yml --- b/core/modules/user/config/schema/user.schema.yml +++ b/core/modules/user/config/schema/user.schema.yml @@ -10,7 +10,7 @@ verify_mail: type: boolean label: 'Require email verification when a visitor creates an account' - password_register: + register_password_set: type: boolean label: 'Require people to choose a password during registration.' notify: diff -u b/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php --- b/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -162,7 +162,7 @@ } } } - elseif (!$config->get('verify_mail') || $config->get('password_register') || $admin_create) { + elseif (!$config->get('verify_mail') || $config->get('register_password_set') || $admin_create) { $form['account']['pass'] = [ '#type' => 'password_confirm', '#size' => 25, diff -u b/core/modules/user/src/AccountSettingsForm.php b/core/modules/user/src/AccountSettingsForm.php --- b/core/modules/user/src/AccountSettingsForm.php +++ b/core/modules/user/src/AccountSettingsForm.php @@ -163,11 +163,11 @@ '#default_value' => $config->get('verify_mail'), '#description' => $this->t('New users will be required to validate their email address prior to logging into the site, and will be assigned a system-generated password. With this setting disabled, users will be logged in immediately upon registering, and may select their own passwords during registration.'), ]; - $form['registration_cancellation']['user_password_register'] = [ + $form['registration_cancellation']['register_password_set'] = [ '#type' => 'checkbox', '#title' => $this->t('Require people to choose a password during registration.'), '#description' => $this->t('If Require e-mail verification is disabled, this setting is automatically enabled.'), - '#default_value' => $config->get('password_register'), + '#default_value' => $config->get('register_password_set'), '#states' => [ // Disable this option if email_verification is unchecked. 'disabled' => [ @@ -492,8 +492,8 @@ ->set('register', $form_state->getValue('user_register')) ->set('password_strength', $form_state->getValue('user_password_strength')) ->set('verify_mail', $form_state->getValue('user_email_verification')) - ->set('password_register', $form_state->getValue('user_password_register')) ->set('cancel_method', $form_state->getValue('user_cancel_method')) + ->set('register_password_set', $form_state->getValue('register_password_set')) ->set('notify.status_activated', $form_state->getValue('user_mail_status_activated_notify')) ->set('notify.status_blocked', $form_state->getValue('user_mail_status_blocked_notify')) ->set('notify.status_canceled', $form_state->getValue('user_mail_status_canceled_notify')) diff -u b/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php --- b/core/modules/user/src/Entity/User.php +++ b/core/modules/user/src/Entity/User.php @@ -144,7 +144,7 @@ // if the account never signed in and if we are // called from the user_register_form and password_register // is set to enabled. - if (!$this->login->value && \Drupal::config('user.settings')->get('password_register') && !$this->original->status->value && $this->status->value) { + if (!$this->login->value && \Drupal::config('user.settings')->get('register_password_set') && !$this->original->status->value && $this->status->value) { $op = 'register_password_set_activation'; } diff -u b/core/modules/user/src/RegisterForm.php b/core/modules/user/src/RegisterForm.php --- b/core/modules/user/src/RegisterForm.php +++ b/core/modules/user/src/RegisterForm.php @@ -71,7 +71,7 @@ $config = $this->config('user.settings'); $admin = $form_state->getValue('administer_users'); - if (!$config->get('verify_mail') || ($config->get('verify_mail') && $config->get('password_register')) || $admin) { + if (!$config->get('verify_mail') || ($config->get('verify_mail') && $config->get('register_password_set')) || $admin) { $pass = $form_state->getValue('pass'); } else { @@ -81,7 +81,7 @@ // If we are not an admin and we try to register and password_register // is set, make sure the status is set to disabled before we save // the newly created account. - if ($config->get('verify_mail') && $config->get('password_register') && !$form_state->getValue('uid') && !$admin) { + if ($config->get('verify_mail') && $config->get('register_password_set') && !$form_state->getValue('uid') && !$admin) { $form_state->setValue('status', 0); } @@ -128,9 +128,9 @@ ])); } // Email verification enabled, but users set a password during registration. - elseif (!$admin && $config->get('register') == UserInterface::REGISTER_VISITORS && $config->get('password_register') && !$account->isActive()) { + elseif (!$admin && $config->get('register') == UserInterface::REGISTER_VISITORS && $config->get('register_password_set') && !$account->isActive()) { // Notify the user. - _user_mail_notify('register_password_set', $account); + _user_mail_notify('register_pending_approval', $account); $this->messenger()->addStatus($this->t('A welcome message with further instructions has been sent to your email address.')); $form_state->setRedirect(''); } diff -u b/core/modules/user/tests/src/Functional/UserRegistrationTest.php b/core/modules/user/tests/src/Functional/UserRegistrationTest.php --- b/core/modules/user/tests/src/Functional/UserRegistrationTest.php +++ b/core/modules/user/tests/src/Functional/UserRegistrationTest.php @@ -21,9 +21,7 @@ use StringTranslationTrait; - use AssertMailTrait { - getMails as drupalGetMails; - } + use AssertMailTrait; /** * Modules to enable. @@ -59,7 +57,7 @@ $edit['name'] = $name = $this->randomMachineName(); $edit['mail'] = $mail = $edit['name'] . '@example.com'; $this->submitForm($edit, $this->t('Create new account')); - $this->assertSession()->responseContains($this->t('A welcome message with further instructions has been sent to your email address.'), 'User registered successfully.'); + $this->assertSession()->responseContains($this->t('A welcome message with further instructions has been sent to your email address.')); /** @var EntityStorageInterface $storage */ $storage = $this->container->get('entity_type.manager')->getStorage('user'); @@ -106,7 +104,7 @@ $edit['pass[pass1]'] = '99999.0'; $edit['pass[pass2]'] = '99999'; $this->submitForm($edit, $this->t('Create new account')); - $this->assertSession()->responseContains($this->t('The specified passwords do not match.'), 'Typing mismatched passwords displays an error message.'); + $this->assertSession()->responseContains($this->t('The specified passwords do not match.')); // Enter a correct password. $edit['pass[pass1]'] = $new_pass = $this->randomMachineName(); @@ -119,7 +117,7 @@ ->loadByProperties(['name' => $name, 'mail' => $mail]); $new_user = reset($accounts); $this->assertNotNull($new_user, 'New account successfully created with matching passwords.'); - $this->assertSession()->responseContains($this->t('Registration successful. You are now logged in.'), 'Users are logged in after registering.'); + $this->assertSession()->responseContains($this->t('Registration successful. You are now logged in.')); $this->drupalLogout(); // Allow registration by site visitors, but require administrator approval. @@ -132,7 +130,7 @@ $edit['pass[pass1]'] = $pass = $this->randomMachineName(); $edit['pass[pass2]'] = $pass; $this->submitForm($edit, $this->t('Create new account')); - $this->assertSession()->responseContains($this->t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.'), 'Users are notified of pending approval'); + $this->assertSession()->responseContains($this->t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.')); // Try to log in before administrator approval. $this->drupalGet('user/login'); @@ -142,7 +140,7 @@ 'pass' => $pass, ]; $this->submitForm($auth, $this->t('Log in')); - $this->assertSession()->responseContains($this->t('The username @name has not been activated or is blocked.', ['@name' => $name]), 'User cannot log in yet.'); + $this->assertSession()->pageTextContains(t('The username @name has not been activated or is blocked.', ['@name' => $name])); // Activate the new account. $accounts = $this->container->get('entity_type.manager')->getStorage('user') @@ -162,7 +160,7 @@ $this->drupalGet('user/login'); $this->assertSession()->statusCodeEquals(200); $this->submitForm($auth, $this->t('Log in')); - $this->assertSession()->responseContains($this->t('Member for'), 'User can log in after administrator approval.'); + $this->assertSession()->responseContains($this->t('Member for')); } /** @@ -175,7 +173,8 @@ $this->config('user.settings') ->set('verify_mail', TRUE) ->set('register', UserInterface::REGISTER_VISITORS) - ->set('password_register', TRUE) + ->set('register_password_set', TRUE) + ->set('notify.register_pending_approval', TRUE) ->save(); $edit = []; @@ -188,7 +187,7 @@ $this->drupalGet('user/register'); $this->assertSession()->statusCodeEquals(200); $this->submitForm($edit, $this->t('Create new account')); - $this->assertSession()->responseContains($this->t('A welcome message with further instructions has been sent to your email address.'), 'Send e-mail to user after registering.'); + $this->assertSession()->responseContains($this->t('A welcome message with further instructions has been sent to your email address.')); // Make sure the user is still blocked. $this->container->get('entity_type.manager')->getStorage('user')->resetCache(); @@ -206,20 +205,25 @@ $this->drupalGet('user/login'); $this->assertSession()->statusCodeEquals(200); $this->submitForm($edit2, $this->t('Log in')); - $this->assertSession()->responseContains($this->t('The username %name has not been activated or is blocked.', ['%name' => $name]), $this->t('User cannot login yet.')); + $this->assertSession()->responseContains($this->t('The username %name has not been activated or is blocked.', ['%name' => $name])); // Try to activate the user. - $_emails = $this->drupalGetMails(); + $new_user->activate(); + $new_user->save(); + $_emails = $this->getMails(); $this->assertCount(2, $_emails); - $email = end($_emails); + $email = reset($_emails); $urls = []; preg_match('#.+user/reset/.+#', $email['body'], $urls); + $this->drupalGet($urls[0]); + $this->drupalPostForm(NULL, [], t('Log in')); - return $urls[0]; + // Change the password. + $password = \Drupal::service('password_generator')->generate(); + $edit = ['pass[pass1]' => $password, 'pass[pass2]' => $password]; + $this->drupalPostForm(NULL, $edit, t('Save')); + $this->assertText(t('The changes have been saved.'), 'Password changed.'); - $_uid = $new_user->id(); - $this->drupalGet($urls[0]); - $this->assertSession()->responseContains($this->t('You have just used your one-time login link. Your account is now active.'), $this->t('User account activated.')); } /** @@ -244,7 +248,7 @@ $this->drupalGet('user/register'); $this->assertSession()->statusCodeEquals(200); $this->submitForm($edit, $this->t('Create new account')); - $this->assertSession()->responseContains($this->t('The email address @email is already taken.', ['@email' => $duplicate_user->getEmail()]), 'Supplying an exact duplicate email address displays an error message'); + $this->assertSession()->pageTextContains($this->t('The email address @email is already taken.', ['@email' => $duplicate_user->getEmail()])); // Attempt to bypass duplicate email validation by adding spaces. $edit['mail'] = ' ' . $duplicate_user->getEmail() . ' '; @@ -252,7 +256,7 @@ $this->drupalGet('user/register'); $this->assertSession()->statusCodeEquals(200); $this->submitForm($edit, $this->t('Create new account')); - $this->assertSession()->responseContains($this->t('The email address @email is already taken.', ['@email' => $duplicate_user->getEmail()]), 'Supplying a duplicate email address with added whitespace displays an error message'); + $this->assertSession()->pageTextContains($this->t('The email address @email is already taken.', ['@email' => $duplicate_user->getEmail()])); } /** @@ -426,7 +430,7 @@ // Check that the field does not appear on the registration form. $this->drupalGet('user/register'); - $this->assertSession()->responseNotContains($field->label(), 'The field does not appear on user registration form'); + $this->assertSession()->responseNotContains($field->label()); $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:core.entity_form_display.user.user.register'); $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:user.settings'); @@ -436,7 +440,7 @@ ->save(); $this->drupalGet('user/register'); - $this->assertSession()->responseContains($field->label(), 'The field appears on user registration form'); + $this->assertSession()->responseContains($field->label()); $this->assertRegistrationFormCacheTagsWithUserFields(); // Check that validation errors are correctly reported. diff -u b/core/modules/user/user.module b/core/modules/user/user.module --- b/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1020,7 +1020,6 @@ * self-registers. * - 'register_pending_approval': Welcome message, user pending admin * approval. - * - 'register_password_set': Welcome message, password set. * - 'register_password_set_activation': Activation message, password set. * - 'password_reset': Password recovery request. * - 'status_activated': Account activated.