public function UserController::resetPass in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/user/src/Controller/UserController.php \Drupal\user\Controller\UserController::resetPass()
Returns the user password reset page.
Parameters
int $uid: UID of user requesting reset.
int $timestamp: The current timestamp.
string $hash: Login link hash.
Return value
array|\Symfony\Component\HttpFoundation\RedirectResponse The form structure or a redirect response.
Throws
\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException If the login link is for a blocked user or invalid user ID.
1 string reference to 'UserController::resetPass'
- user.routing.yml in core/
modules/ user/ user.routing.yml - core/modules/user/user.routing.yml
File
- core/
modules/ user/ src/ Controller/ UserController.php, line 89 - Contains \Drupal\user\Controller\UserController.
Class
- UserController
- Controller routines for user routes.
Namespace
Drupal\user\ControllerCode
public function resetPass($uid, $timestamp, $hash) {
$account = $this
->currentUser();
$config = $this
->config('user.settings');
// 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();
}
else {
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">logout</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>');
}
}
// The current user is not logged in, so check the parameters.
// Time out, in seconds, until login URL expires.
$timeout = $config
->get('password_reset_timeout');
$current = REQUEST_TIME;
/* @var \Drupal\user\UserInterface $user */
$user = $this->userStorage
->load($uid);
// Verify that the user exists and is active.
if ($user && $user
->isActive()) {
// No time out for first time login.
if ($user
->getLastLoginTime() && $current - $timestamp > $timeout) {
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.'), 'error');
return $this
->redirect('user.pass');
}
elseif ($user
->isAuthenticated() && $timestamp >= $user
->getLastLoginTime() && $timestamp <= $current && Crypt::hashEquals($hash, user_pass_rehash($user, $timestamp))) {
$expiration_date = $user
->getLastLoginTime() ? $this->dateFormatter
->format($timestamp + $timeout) : NULL;
return $this
->formBuilder()
->getForm('Drupal\\user\\Form\\UserPasswordResetForm', $user, $expiration_date, $timestamp, $hash);
}
else {
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.'), 'error');
return $this
->redirect('user.pass');
}
}
// Blocked or invalid user ID, so deny access. The parameters will be in the
// watchdog's URL for the administrator to check.
throw new AccessDeniedHttpException();
}