Commit f69b3256 authored by Nigel Cunningham's avatar Nigel Cunningham Committed by Paulo Henrique Cota Starling
Browse files

Issue #3213457 by Sophie.SK, larisse, paulocs, NigelCunningham, andypost,...

Issue #3213457 by Sophie.SK, larisse, paulocs, NigelCunningham, andypost, hmendes: Support for Masquerade module
parent 253c2081
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ services:
        - '@entity_type.manager'
        - '@messenger'
        - '@request_stack'
        - '@?masquerade'
      tags:
        - {name: event_subscriber}
  password_policy.validator:
+19 −1
Original line number Diff line number Diff line
@@ -49,6 +49,13 @@ class PasswordPolicyEventSubscriber implements EventSubscriberInterface {
   */
  protected $request;

  /**
   * The Masquerade service if it exists, or NULL.
   *
   * @var \Drupal\masquerade\Masquerade|null
   */
  protected $masquerade;

  /**
   * PasswordPolicyEventSubscriber constructor.
   *
@@ -60,15 +67,18 @@ class PasswordPolicyEventSubscriber implements EventSubscriberInterface {
   *   The messenger service.
   * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
   *   The request stack.
   * @param \Drupal\masquerade\Masquerade|null $masquerade
   *   The Masquerade service if it exists.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function __construct(AccountProxyInterface $currentUser, EntityTypeManagerInterface $entityTypeManager, MessengerInterface $messenger, RequestStack $requestStack) {
  public function __construct(AccountProxyInterface $currentUser, EntityTypeManagerInterface $entityTypeManager, MessengerInterface $messenger, RequestStack $requestStack, $masquerade = NULL) {
    $this->currentUser = $currentUser;
    $this->messenger = $messenger;
    $this->request = $requestStack->getCurrentRequest();
    $this->userStorage = $entityTypeManager->getStorage('user');
    $this->masquerade = $masquerade;
  }

  /**
@@ -106,6 +116,14 @@ class PasswordPolicyEventSubscriber implements EventSubscriberInterface {
        $user_expired = $user_expired['value'];
      }

      // Bail early if the current user is masquerading. Masquerade should not
      // force a password reset.
      if (isset($this->masquerade)) {
        if ($this->masquerade->isMasquerading()) {
          return;
        }
      }

      // Save the token passed in the URL when the user access the site via
      // one time login.
      $session = $this->request->getSession();