You are here

public function ChangePasswordResetForm::submitForm in Password Separate Form 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/ChangePasswordResetForm.php, line 102

Class

ChangePasswordResetForm
Form controller for the user password forms.

Namespace

Drupal\change_pwd_page\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $user = $form_state
    ->getValue('user');
  user_login_finalize($user);
  $this->logger
    ->notice('User %name used one-time login link at time %timestamp.', [
    '%name' => $user
      ->getDisplayName(),
    '%timestamp' => $form_state
      ->getValue('timestamp'),
  ]);
  $this
    ->messenger()
    ->addStatus($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::randomBytesBase64(55);
  $_SESSION['pass_reset_' . $user
    ->id()] = $token;
  $form_state
    ->setRedirect('change_pwd_page.change_password_form', [
    'user' => $user
      ->id(),
  ], [
    'query' => [
      'pass-reset-token' => $token,
    ],
    'absolute' => TRUE,
  ]);
}