Commit d1aa55d8 authored by Kristof De Jaeger's avatar Kristof De Jaeger
Browse files

Issue #3259620 by swentel: Add 'reset password' link on reader login form

parent 098d1e78
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -96,6 +96,15 @@ function reader_form_user_login_form_alter(&$form, FormStateInterface $form_stat
  \Drupal::service('reader.form_alter')->alterLoginForm($form, $form_state);
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function reader_form_user_pass_reset_alter(&$form, FormStateInterface $form_state) {
  if (isset($_SESSION['use_reader_theme'])) {
    \Drupal::service('reader.form_alter')->alterResetPasswordForm($form);
  }
}

/**
 * Prepares variables for list of available node type links and other content.
 *
+11 −0
Original line number Diff line number Diff line
@@ -145,3 +145,14 @@ reader.login:
  options:
    _maintenance_access: TRUE
    _reader_theme: 'reader_theme'

reader.password:
  path: '/reader/user/password'
  defaults:
    _form: '\Drupal\reader\Form\ReaderUserPasswordForm'
    _title: 'Reset your password'
  requirements:
    _access: 'TRUE'
  options:
    _maintenance_access: TRUE
    _reader_theme: 'reader_theme'
+22 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\reader\Form;

use Drupal\Core\Form\FormStateInterface;
use Drupal\user\Form\UserPasswordForm;

/**
 * Provides the user password form.
 */
class ReaderUserPasswordForm extends UserPasswordForm {

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $_SESSION['use_reader_theme'] = TRUE;
    parent::submitForm($form, $form_state);
    $form_state->setRedirect('reader.login');
  }

}
+22 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
@@ -113,6 +114,7 @@ class ReaderFormAlter implements ReaderFormAlterInterface {
      return;
    }

    $form['reset_link'] = ['#markup' => '<p class="user-link">' . Link::createFromRoute($this->t('Forgot password?'), 'reader.password')->toString() . '</p>'];
    $form['#submit'][] = [$this, 'loginSubmit'];
  }

@@ -139,6 +141,26 @@ class ReaderFormAlter implements ReaderFormAlterInterface {
    }
  }

  /**
   * {@inheritdoc}
   */
  public function alterResetPasswordForm(array &$form) {
    unset($_SESSION['use_reader_theme']);
    $form['#action'] .= '?destination=/reader';
  }

  /**
   * Submit callback after reset login.
   *
   * @param array $form
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *
   * @see alterLoginForm();
   */
  public function resetSubmit(array &$form, FormStateInterface $form_state) {
    $form_state->setRedirect('reader.home');
  }

  /**
   * Returns whether this is a reader content route or not.
   *
+7 −0
Original line number Diff line number Diff line
@@ -34,4 +34,11 @@ interface ReaderFormAlterInterface {
   */
  public function alterLoginForm(array &$form, FormStateInterface $form_state);

  /**
   * Alter the user reset password form.
   *
   * @param array $form
   */
  public function alterResetPasswordForm(array &$form);

}
Loading