ce8c7cca1d713633143e8e2fbfe87ef279a21651
[yaffs-website] / web / core / modules / user / src / Form / UserPasswordResetForm.php
1 <?php
2
3 namespace Drupal\user\Form;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\Core\Session\AccountInterface;
7 use Drupal\Core\Form\FormBase;
8 use Drupal\Core\Url;
9
10 /**
11  * Form controller for the user password forms.
12  */
13 class UserPasswordResetForm extends FormBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function getFormId() {
19     return 'user_pass_reset';
20   }
21
22   /**
23    * {@inheritdoc}
24    *
25    * @param array $form
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
33    *   not expire.
34    * @param int $timestamp
35    *   The current timestamp.
36    * @param string $hash
37    *   Login link hash.
38    */
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');
43     }
44     else {
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');
48     }
49
50     $form['help'] = ['#markup' => '<p>' . $this->t('This login can be used only once.') . '</p>'];
51     $form['actions'] = ['#type' => 'actions'];
52     $form['actions']['submit'] = [
53       '#type' => 'submit',
54       '#value' => $this->t('Log in'),
55     ];
56     $form['#action'] = Url::fromRoute('user.reset.login', [
57       'uid' => $user->id(),
58       'timestamp' => $timestamp,
59       'hash' => $hash,
60     ])->toString();
61     return $form;
62   }
63
64   /**
65    * {@inheritdoc}
66    */
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.
70   }
71
72 }