diff --git a/core/modules/user/lib/Drupal/user/Tests/UserPasswordResetTest.php b/core/modules/user/lib/Drupal/user/Tests/UserPasswordResetTest.php index bb70f78..60ac819 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserPasswordResetTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserPasswordResetTest.php @@ -34,7 +34,7 @@ function testUserPasswordReset() { $edit = array('name' => $account->name); $this->drupalPost('user/password', $edit, t('E-mail new password')); // Confirm the password reset. - $this->assertText(t('Further instructions have been sent to your e-mail address.'), 'Password reset instructions mailed message displayed.'); + $this->assertText(format_string('Further instructions have been sent to @name.', array('@name' => $account->name)), 'Password reset instructions mailed message displayed.'); } /** @@ -55,6 +55,6 @@ function testUserPasswordResetExpired() { $timeout = config('user.settings')->get('password_reset_timeout'); $bogus_timestamp = REQUEST_TIME - $timeout - 60; $this->drupalGet("user/reset/$account->uid/$bogus_timestamp/" . user_pass_rehash($account->pass, $bogus_timestamp, $account->login)); - $this->assertText(t('You have tried to use a one-time login link that has expired. Please request a new one using the form below.'), 'Expired password reset request rejected.'); + $this->assertText('You have tried to use a one-time login link that has expired. Please request a new one using the form below.', 'Expired password reset request rejected.'); } } diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc index 20af863..ec1d903 100644 --- a/core/modules/user/user.pages.inc +++ b/core/modules/user/user.pages.inc @@ -59,35 +59,60 @@ function user_pass() { return $form; } +/** + * Form builder; Validation of the request for password reset. + * + * @ingroup forms + * @see user_pass() + * @see user_pass_submit() + */ function user_pass_validate($form, &$form_state) { $name = trim($form_state['values']['name']); - // Try to load by email. - $users = entity_load_multiple_by_properties('user', array('mail' => $name, 'status' => '1')); - $account = reset($users); - if (!$account) { - // No success, try to load by name. - $users = entity_load_multiple_by_properties('user', array('name' => $name, 'status' => '1')); - $account = reset($users); - } - if (isset($account->uid)) { - form_set_value(array('#parents' => array('account')), $account, $form_state); + + if (empty($name)) { + form_set_error('name', t('You have to enter an username or e-mail address.')); } else { - form_set_error('name', t('Sorry, %name is not recognized as a username or an e-mail address.', array('%name' => $name))); + // Try to load by email. + $users = entity_load_multiple_by_properties('user', array('mail' => $name, 'status' => '1')); + $account = reset($users); + if (!$account) { + // No success, try to load by name. + $users = entity_load_multiple_by_properties('user', array('name' => $name, 'status' => '1')); + $account = reset($users); + } + if (isset($account->uid)) { + form_set_value(array('#parents' => array('account')), $account, $form_state); + } } + } +/** + * Form builder; Submission of the request for password reset. + * + * @ingroup forms + * @see user_pass() + * @see user_pass_validate() + */ function user_pass_submit($form, &$form_state) { $language_interface = language(LANGUAGE_TYPE_INTERFACE); - - $account = $form_state['values']['account']; - // Mail one time login URL and instructions using current language. - $mail = _user_mail_notify('password_reset', $account, $language_interface->langcode); - if (!empty($mail)) { - watchdog('user', 'Password reset instructions mailed to %name at %email.', array('%name' => $account->name, '%email' => $account->mail)); - drupal_set_message(t('Further instructions have been sent to your e-mail address.')); + + $name = trim($form_state['values']['name']); + if (!empty($form_state['values']['account'])) { + $account = $form_state['values']['account']; + // Mail one time login URL and instructions using current language. + $mail = _user_mail_notify('password_reset', $account, $language_interface->langcode); + if (!empty($mail)) { + watchdog('user', 'Password reset instructions mailed to %name at %email.', array('%name' => $account->name, '%email' => $account->mail)); + } } - + else { + watchdog('user', 'Password reset form was used containing an unknown account: %name', array('%name' => $name), WATCHDOG_WARNING); + } + + drupal_set_message(t('Further instructions have been sent to %name.', array('%name' => $name))); + $form_state['redirect'] = 'user'; return; }