3 namespace Drupal\user\Form;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\Core\Session\AccountInterface;
7 use Drupal\Core\Form\FormBase;
11 * Form controller for the user password forms.
13 class UserPasswordResetForm extends FormBase {
18 public function getFormId() {
19 return 'user_pass_reset';
26 * An associative array containing the structure of the form.
27 * @param \Drupal\Core\Form\FormStateInterface $form_state
28 * The current state of the form.
29 * @param \Drupal\Core\Session\AccountInterface $user
30 * User requesting reset.
31 * @param string $expiration_date
32 * Formatted expiration date for the login link, or NULL if the link does
34 * @param int $timestamp
35 * The current timestamp.
39 public function buildForm(array $form, FormStateInterface $form_state, AccountInterface $user = NULL, $expiration_date = NULL, $timestamp = NULL, $hash = NULL) {
40 if ($expiration_date) {
41 $form['message'] = ['#markup' => $this->t('<p>This is a one-time login for %user_name and will expire on %expiration_date.</p><p>Click on this button to log in to the site and change your password.</p>', ['%user_name' => $user->getUsername(), '%expiration_date' => $expiration_date])];
42 $form['#title'] = $this->t('Reset password');
45 // No expiration for first time login.
46 $form['message'] = ['#markup' => $this->t('<p>This is a one-time login for %user_name.</p><p>Click on this button to log in to the site and change your password.</p>', ['%user_name' => $user->getUsername()])];
47 $form['#title'] = $this->t('Set password');
50 $form['help'] = ['#markup' => '<p>' . $this->t('This login can be used only once.') . '</p>'];
51 $form['actions'] = ['#type' => 'actions'];
52 $form['actions']['submit'] = [
54 '#value' => $this->t('Log in'),
56 $form['#action'] = Url::fromRoute('user.reset.login', [
58 'timestamp' => $timestamp,
67 public function submitForm(array &$form, FormStateInterface $form_state) {
68 // This form works by submitting the hash and timestamp to the user.reset
69 // route with a 'login' action.