function OneTimeAuthentication::generateOneTimeLoginUrl

Same name and namespace in other branches
  1. 11.x core/modules/user/src/OneTimeAuthentication.php \Drupal\user\OneTimeAuthentication::generateOneTimeLoginUrl()

Generates a unique URL for a user to log in and reset their password.

Parameters

\Drupal\user\UserInterface $account: An object containing the user account.

array $options: (optional) A keyed array of settings. Supported options are:

  • langcode: A language code to be used when generating locale-sensitive URLs. If langcode is NULL the users preferred language is used.

bool $immediate: Whether or not to perform the login action immediately when the URL is opened. Defaults to false.

File

core/modules/user/src/OneTimeAuthentication.php, line 97

Class

OneTimeAuthentication
Generate and verify one time authentication codes.

Namespace

Drupal\user

Code

public function generateOneTimeLoginUrl(UserInterface $account, array $options = [], bool $immediate = FALSE) : Url {
  $timestamp = $this->time
    ->getCurrentTime();
  $langcode = $options['langcode'] ?? $account->getPreferredLangcode();
  $routeName = $immediate ? 'user.reset.login' : 'user.reset';
  return Url::fromRoute($routeName, [
    'uid' => $account->id(),
    'timestamp' => $timestamp,
    'hash' => $this->generateHmac($account, $timestamp),
  ], [
    'absolute' => TRUE,
    'language' => $this->languageManager
      ->getLanguage($langcode),
  ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.