diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc index 20af863..65d9fbd 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); - + + $name = trim($form_state['values']['name']); $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.')); + if (!empty($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)); + } + + drupal_set_message(t('Further instructions have been sent to %name.', array('%name' => $name)), WATCHDOG_WARNING); + $form_state['redirect'] = 'user'; return; }