diff -u b/core/modules/user/lib/Drupal/user/Form/UserPasswordResetForm.php b/core/modules/user/lib/Drupal/user/Form/UserPasswordResetForm.php --- b/core/modules/user/lib/Drupal/user/Form/UserPasswordResetForm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserPasswordResetForm.php @@ -7,11 +7,9 @@ namespace Drupal\user\Form; -use Drupal\Core\Controller\ControllerInterface; -use Drupal\Core\Form\FormInterface; +use Drupal\Core\Form\FormBase; use Drupal\user\UserStorageControllerInterface; -use Drupal\Core\Routing\PathBasedGeneratorInterface; -use Drupal\Core\StringTranslation\TranslationManager; +use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Config\Config; use Drupal\Component\Utility\Crypt; use Drupal\Core\Datetime\Date; @@ -23,7 +21,7 @@ /** * Form controller for the user password reset form. */ -class UserPasswordResetForm implements FormInterface, ControllerInterface { +class UserPasswordResetForm extends FormBase { /** * The user entity storage controller. @@ -33,16 +31,9 @@ protected $userStorageController; /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationManager - */ - protected $translationManager; - - /** * The URL generator service. * - * @var \Drupal\Core\Routing\PathBasedGeneratorInterface + * @var \Drupal\Core\Routing\UrlGeneratorInterface */ protected $urlGenerator; @@ -65,18 +56,15 @@ * * @param \Drupal\user\UserStorageControllerInterface $storage_controller * The user storage controller. - * @param \Drupal\Core\StringTranslation\TranslationManager $translation_manager - * The translation manager service. - * @param \Drupal\Core\Routing\PathBasedGeneratorInterface $url_generator + * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator * The URL generator service. * @param \Drupal\Core\Config\Config $user_config * The user settings config object. * @param \Drupal\Core\Datetime\Date $date * The date service. */ - public function __construct(UserStorageControllerInterface $storage_controller, TranslationManager $translation_manager, PathBasedGeneratorInterface $url_generator, Config $user_config, Date $date) { + public function __construct(UserStorageControllerInterface $storage_controller, UrlGeneratorInterface $url_generator, Config $user_config, Date $date) { $this->userStorageController = $storage_controller; - $this->translationManager = $translation_manager; $this->urlGenerator = $url_generator; $this->userConfig = $user_config; $this->date = $date; @@ -88,7 +76,6 @@ public static function create(ContainerInterface $container) { return new static( $container->get('plugin.manager.entity')->getStorageController('user'), - $container->get('string_translation'), $container->get('url_generator'), $container->get('config.factory')->get('user.settings'), $container->get('date') @@ -105,28 +92,28 @@ /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, $uid = NULL, $timestamp = NULL, $hash = NULL, Request $request = NULL, $operation = 'confirm') { - $account = $request->attributes->get('_account'); + public function buildForm(array $form, array &$form_state, $uid = NULL, $timestamp = NULL, $hash = NULL, $operation = 'confirm') { + $account = $this->getCurrentUser(); // When processing the one-time login link, we have to make sure that a user // isn't already logged in. if ($account->isAuthenticated()) { // The existing user is already logged in. if ($account->id() == $uid) { - drupal_set_message($this->translationManager->translate('You are logged in as %user. Change your password.', array('%user' => $account->getUsername(), '!user_edit' => url("user/" . $account->id() . "/edit")))); + drupal_set_message($this->t('You are logged in as %user. Change your password.', array('%user' => $account->getUsername(), '!user_edit' => url("user/" . $account->id() . "/edit")))); } // A different user is already logged in on the computer. else { $reset_link_user = $this->userStorageController->load($uid); if (!empty($reset_link_user)) { - drupal_set_message($this->translationManager->translate('Another user (%other_user) is already logged into the site on this computer, but you tried to use a one-time link for user %resetting_user. Please logout and try using the link again.', - array('%other_user' => $account->getUsername(), '%resetting_user' => $reset_link_user->getUsername(), '!logout' => $this->urlGenerator->generateFromPath('user/logout')))); + drupal_set_message($this->t('Another user (%other_user) is already logged into the site on this computer, but you tried to use a one-time link for user %resetting_user. Please logout and try using the link again.', + array('%other_user' => $account->getUsername(), '%resetting_user' => $reset_link_user->getUsername(), '!logout' => $this->urlGenerator->generateFromRoute('user_logout')))); } else { // Invalid one-time link specifies an unknown user. - drupal_set_message($this->translationManager->translate('The one-time login link you clicked is invalid.')); + drupal_set_message($this->t('The one-time login link you clicked is invalid.')); } } - return new RedirectResponse($this->urlGenerator->generateFromPath('', array('absolute' => TRUE))); + return new RedirectResponse($this->urlGenerator->generateFromRoute('', array(), array('absolute' => TRUE))); } else { // Time out, in seconds, until login URL expires. @@ -137,8 +124,8 @@ if ($user->isActive()) { // No time out for first time login. if ($user->getLastLoginTime() && $current - $timestamp > $timeout) { - drupal_set_message($this->translationManager->translate('You have tried to use a one-time login link that has expired. Please request a new one using the form below.')); - return new RedirectResponse($this->urlGenerator->generateFromPath('user/password', array('absolute' => TRUE))); + drupal_set_message($this->t('You have tried to use a one-time login link that has expired. Please request a new one using the form below.')); + return new RedirectResponse($this->urlGenerator->generateFromRoute('user_pass', array(), array('absolute' => TRUE))); } elseif ($user->isAuthenticated() && $timestamp >= $user->getLastLoginTime() && $timestamp <= $current && $hash == user_pass_rehash($user->getPassword(), $timestamp, $user->getLastLoginTime())) { // First stage is a confirmation form, then login @@ -148,7 +135,7 @@ // user, which invalidates further use of the one-time login link. user_login_finalize($user); watchdog('user', 'User %name used one-time login link at time %timestamp.', array('%name' => $user->getUsername(), '%timestamp' => $timestamp)); - drupal_set_message($this->translationManager->translate('You have just used your one-time login link. It is no longer necessary to use this link to log in. Please change your password.')); + drupal_set_message($this->t('You have just used your one-time login link. It is no longer necessary to use this link to log in. Please change your password.')); // Let the user's password be changed without the current password check. $token = Crypt::randomStringHashed(55); $_SESSION['pass_reset_' . $user->id()] = $token; @@ -160,21 +147,21 @@ else { if (!$user->getLastLoginTime()) { // No expiration for first time login. - $form['message'] = array('#markup' => $this->translationManager->translate('

This is a one-time login for %user_name.

Click on this button to log in to the site and change your password.

', array('%user_name' => $user->getUsername()))); + $form['message'] = array('#markup' => $this->t('

This is a one-time login for %user_name.

Click on this button to log in to the site and change your password.

', array('%user_name' => $user->getUsername()))); } else { - $form['message'] = array('#markup' => $this->translationManager->translate('

This is a one-time login for %user_name and will expire on %expiration_date.

Click on this button to log in to the site and change your password.

', array('%user_name' => $user->getUsername(), '%expiration_date' => $this->date->format($timestamp + $timeout)))); + $form['message'] = array('#markup' => $this->t('

This is a one-time login for %user_name and will expire on %expiration_date.

Click on this button to log in to the site and change your password.

', array('%user_name' => $user->getUsername(), '%expiration_date' => $this->date->format($timestamp + $timeout)))); } - $form['help'] = array('#markup' => '

' . $this->translationManager->translate('This login can be used only once.') . '

'); + $form['help'] = array('#markup' => '

' . $this->t('This login can be used only once.') . '

'); $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->translationManager->translate('Log in')); - $form['#action'] = $this->urlGenerator->generateFromPath("user/reset/$uid/$timestamp/$hash/login"); + $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Log in')); + $form['#action'] = $this->urlGenerator->generateFromRoute('user_pass_reset', array('uid' => $uid, 'timestamp' => $timestamp, 'hash' => $hash, 'operation' => 'login')); return $form; } } else { - drupal_set_message($this->translationManager->translate('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.')); - return new RedirectResponse($this->urlGenerator->generateFromPath('user/password', array('absolute' => TRUE))); + drupal_set_message($this->t('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.')); + return new RedirectResponse($this->urlGenerator->generateFromRoute('user_pass', array(), array('absolute' => TRUE))); } } else { @@ -186,13 +173,6 @@ } /** - * {@inheritdoc} - */ - public function validateForm(array &$form, array &$form_state) { - - } - - /** * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) {