You are here

public function User::resetPass in Simple Password Reset 8

Displays user password reset form.

File

src/Controller/User.php, line 16

Class

User
Alter User Reset password page.

Namespace

Drupal\simple_pass_reset\Controller

Code

public function resetPass(Request $request, $uid, $timestamp, $hash) {

  /** @var \Drupal\user\UserInterface $user */
  $user = \Drupal::entityTypeManager()
    ->getStorage('user')
    ->load($uid);
  $account = \Drupal::currentUser();

  // The current user is already logged in.
  if ($account
    ->isAuthenticated() && $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,
    ]);
  }
  $formObject = \Drupal::service('entity_type.manager')
    ->getFormObject('user', 'default')
    ->setEntity($user);
  return $this
    ->formBuilder()
    ->getForm($formObject);
}