UserController::resetPass

public UserController::resetPass(Request $request, $uid, $timestamp, $hash)

Redirects to the user password reset form.

In order to never disclose a reset link via a referrer header this controller must always return a redirect response.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request.

int $uid: User ID of the user requesting reset.

int $timestamp: The current timestamp.

string $hash: Login link hash.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse The redirect response.

File

core/modules/user/src/Controller/UserController.php, line 100

Class

UserController
Controller routines for user routes.

Namespace

Drupal\user\Controller

Code

public function resetPass(Request $request, $uid, $timestamp, $hash) {
  $account = $this->currentUser();
  // When processing the one-time login link, we have to make sure that a user
  // isn't already logged in.
  if ($account->isAuthenticated()) {
    // The current user is already logged in.
    if ($account->id() == $uid) {
      user_logout();
      // We need to begin the redirect process again because logging out will
      // destroy the session.
      return $this->redirect(
      'user.reset', 
      [
        'uid' => $uid,
        'timestamp' => $timestamp,
        'hash' => $hash,
      ]
      );
    }
    // A different user is already logged in on the computer.
    else {
      /** @var \Drupal\user\UserInterface $reset_link_user */
      if ($reset_link_user = $this->userStorage->load($uid)) {
        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 <a href=":logout">log out</a> and try using the link again.', 
        array('%other_user' => $account->getUsername(), '%resetting_user' => $reset_link_user->getUsername(), ':logout' => $this->url('user.logout'))), 'warning');
      }
      else {
        // Invalid one-time link specifies an unknown user.
        drupal_set_message($this->t('The one-time login link you clicked is invalid.'), 'error');
      }
      return $this->redirect('<front>');
    }
  }

  $session = $request->getSession();
  $session->set('pass_reset_hash', $hash);
  $session->set('pass_reset_timeout', $timestamp);
  return $this->redirect(
  'user.reset.form', 
  ['uid' => $uid]
  );
}
doc_Drupal
2016-10-29 09:52:27
Comments
Leave a Comment

Please login to continue.