diff --git a/core/modules/user/lib/Drupal/user/UserPasswordController.php b/core/modules/user/lib/Drupal/user/UserPasswordController.php new file mode 100644 index 0000000..d8ff213 --- /dev/null +++ b/core/modules/user/lib/Drupal/user/UserPasswordController.php @@ -0,0 +1,66 @@ + 'textfield', + '#title' => t('Username or e-mail address'), + '#size' => 60, + '#maxlength' => max(USERNAME_MAX_LENGTH, EMAIL_MAX_LENGTH), + '#required' => TRUE, + ); + // Allow logged in users to request this also. + if ($user->uid > 0) { + $form['name']['#type'] = 'value'; + $form['name']['#value'] = $user->mail; + $form['mail'] = array( + '#prefix' => '

', + '#markup' => t('Password reset instructions will be mailed to %email. You must log out to use the password reset link in the e-mail.', array('%email' => $user->mail)), + '#suffix' => '

', + ); + } + else { + $form['name']['#default_value'] = $request->query->get('name'); + } + $form['actions'] = array('#type' => 'actions'); + $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('E-mail new password')); + + return $form; + } + +} diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 9a1b32c..ec6207a 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -911,12 +911,10 @@ function user_menu() { $items['user/password'] = array( 'title' => 'Request new password', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('user_pass'), - 'access callback' => TRUE, 'type' => MENU_LOCAL_TASK, - 'file' => 'user.pages.inc', + 'route_name' => 'user_pass', ); + $items['user/reset/%/%/%'] = array( 'title' => 'Reset password', 'page callback' => 'drupal_get_form', diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc index 0a86e67..57bbd5a 100644 --- a/core/modules/user/user.pages.inc +++ b/core/modules/user/user.pages.inc @@ -11,42 +11,6 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\HttpKernelInterface; -/** - * Form builder; Request a password reset. - * - * @ingroup forms - * @see user_pass_validate() - * @see user_pass_submit() - */ -function user_pass() { - global $user; - - $form['name'] = array( - '#type' => 'textfield', - '#title' => t('Username or e-mail address'), - '#size' => 60, - '#maxlength' => max(USERNAME_MAX_LENGTH, EMAIL_MAX_LENGTH), - '#required' => TRUE, - ); - // Allow logged in users to request this also. - if ($user->uid > 0) { - $form['name']['#type'] = 'value'; - $form['name']['#value'] = $user->mail; - $form['mail'] = array( - '#prefix' => '

', - '#markup' => t('Password reset instructions will be mailed to %email. You must log out to use the password reset link in the e-mail.', array('%email' => $user->mail)), - '#suffix' => '

', - ); - } - else { - $form['name']['#default_value'] = Drupal::Request()->query->get('name'); - } - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('E-mail new password')); - - return $form; -} - function user_pass_validate($form, &$form_state) { $name = trim($form_state['values']['name']); // Try to load by email. diff --git a/core/modules/user/user.routing.yml b/core/modules/user/user.routing.yml index 0798e1d..338d417 100644 --- a/core/modules/user/user.routing.yml +++ b/core/modules/user/user.routing.yml @@ -25,3 +25,10 @@ user_account_settings: _form: '\Drupal\user\AccountSettingsForm' requirements: _permission: 'administer users' + +user_pass: + pattern: 'user/password' + defaults: + _controller: '\Drupal\user\UserPasswordController::passwordUser' + requirements: + _access: 'TRUE'