Commit 8a7a31cf authored by abdulaziz  zaid 🇸🇦's avatar abdulaziz zaid 🇸🇦
Browse files

Issue #3254512 To switch users with the module Masquerade

parent aa084c9c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
services:
    tfa_event_subscriber:
        class: Drupal\email_tfa\EventSubscriber\EmailTfaSubscriber
        arguments: ['@current_user', '@config.factory', '@current_route_match' ,'@tempstore.private' , '@messenger' , '@request_stack' ,'@plugin.manager.mail' ,'@language_manager']
        arguments: ['@current_user', '@config.factory', '@current_route_match' ,'@tempstore.private' , '@messenger' , '@request_stack' ,'@plugin.manager.mail' ,'@language_manager' ,'@module_handler']
        tags:
            - {name: event_subscriber}
+10 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\email_tfa\EventSubscriber;

use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
@@ -101,8 +102,10 @@ class EmailTfaSubscriber implements EventSubscriberInterface {
   *   The mail manager.
   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
   *   The language manager.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
   *   The moduleHandler.
   */
  public function __construct(AccountInterface $account, ConfigFactoryInterface $config_factory, RouteMatchInterface $route_match, PrivateTempStoreFactory $temp_store_factory, MessengerInterface $messenger, RequestStack $request_stack, MailManagerInterface $mail_manager, LanguageManagerInterface $language_manager) {
  public function __construct(AccountInterface $account, ConfigFactoryInterface $config_factory, RouteMatchInterface $route_match, PrivateTempStoreFactory $temp_store_factory, MessengerInterface $messenger, RequestStack $request_stack, MailManagerInterface $mail_manager, LanguageManagerInterface $language_manager, ModuleHandlerInterface $moduleHandler) {
    $this->account = $account;
    $this->config = $config_factory->get('email_tfa.settings');
    $this->routeMatch = $route_match;
@@ -111,7 +114,7 @@ class EmailTfaSubscriber implements EventSubscriberInterface {
    $this->request = $request_stack->getCurrentRequest();
    $this->mailManager = $mail_manager;
    $this->languageManager = $language_manager;

    $this->moduleHandler = $moduleHandler;
  }

  /**
@@ -159,6 +162,11 @@ class EmailTfaSubscriber implements EventSubscriberInterface {
        }
      }

      if ($this->moduleHandler->moduleExists('masquerade')) {
        if (\Drupal::service('masquerade')->isMasquerading()) {
          $result = FALSE;
        }
      }
    }
    // Continue if one of the conditions above succeeds ( res = true ).
    if ($result) {