diff --git a/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php index 1a38a2d..053a5ef 100644 --- a/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -424,11 +424,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { if ($account->isAuthenticated()) { $name_taken = (bool) db_select('users_field_data', 'ufd') - ->condition( - db_or() - ->condition('ufd.name', db_like($form_state->getValue('name')), 'LIKE') - ->condition('ufd.mail', db_like($form_state->getValue('name')), 'LIKE') - ) + ->condition('ufd.name', db_like($form_state->getValue('name')), 'LIKE') ->condition('ufd.uid', $account->id(), '<>') ->range(0, 1) ->countQuery() @@ -459,11 +455,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { if (!empty($mail)) { if ($account->isAuthenticated()) { $mail_taken = (bool) db_select('users_field_data', 'ufd') - ->condition( - db_or() - ->condition('ufd.mail', db_like($form_state->getValue('mail')), 'LIKE') - ->condition('ufd.name', db_like($form_state->getValue('mail')), 'LIKE') - ) + ->condition('ufd.mail', db_like($form_state->getValue('mail')), 'LIKE') ->condition('ufd.uid', $account->id(), '<>') ->range(0, 1) ->countQuery() diff --git a/core/modules/user/src/Form/UserPasswordForm.php b/core/modules/user/src/Form/UserPasswordForm.php index df48f23..8d1f62f 100644 --- a/core/modules/user/src/Form/UserPasswordForm.php +++ b/core/modules/user/src/Form/UserPasswordForm.php @@ -90,7 +90,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { if ($form_state->getValue('step') == 1) { $form['name'] = array( '#type' => 'textfield', - '#title' => t('Username or email address'), + '#title' => $this->t('Username or email address'), '#size' => 60, '#maxlength' => max(USERNAME_MAX_LENGTH, Email::EMAIL_MAX_LENGTH), '#required' => TRUE, @@ -128,7 +128,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { } $form['choose_account'] = array( '#type' => 'radios', - '#title' => t('Choose account'), + '#title' => $this->t('Choose account'), '#required' => TRUE, '#prefix' => "

" . $this->t("There is a username conflict with the email address @email. Please select which account password to reset.", array('@email' => $form_state->getStorage()['name'])) . "

", '#options' => $options, diff --git a/core/modules/user/src/Tests/UserEditTest.php b/core/modules/user/src/Tests/UserEditTest.php index 457c169..83c7ecd 100644 --- a/core/modules/user/src/Tests/UserEditTest.php +++ b/core/modules/user/src/Tests/UserEditTest.php @@ -103,4 +103,29 @@ function testUserWithoutEmailEdit() { $this->assertRaw(t("The changes have been saved.")); } + /** + * Check that existing users whose username matches another user's email + * address or vice versa are not forced to update their username or email + * address. + */ + function testUserEditWithConflicts() { + $user_with_email = $this->drupalCreateUser(); + $user_with_name = $this->drupalCreateUser(); + + // Change the second user's username to the same value as the first user's + // email address. + $user_with_name->name = $user_with_email->mail; + $user_with_name->save(); + + // Test that the first user can save their account with no errors. + $this->drupalLogin($user_with_email); + $this->drupalPostForm("user/" . $user_with_email->id() . "/edit", array(), t('Save')); + $this->assertText(t("The changes have been saved."), "The user does not need to change their username if it matches another user's email address."); + $this->drupalLogout(); + + // Test that the second user can save their account with no errors. + $this->drupalLogin($user_with_name); + $this->drupalPostForm("user/" . $user_with_name->id() . "/edit", array(), t('Save')); + $this->assertText(t("The changes have been saved."), "The user does not need to change their email address if it matches another user's username."); + } }