You are here

public function TfaContext::__construct in Two-factor Authentication (TFA) 8

TfaContextInterface constructor.

Parameters

\Drupal\tfa\TfaValidationPluginManager $tfa_validation_manager: The plugin manager for TFA validation plugins.

\Drupal\tfa\TfaLoginPluginManager $tfa_plugin_manager: The plugin manager for TFA login plugins.

\Drupal\Core\Config\ConfigFactoryInterface $config_factory: The configuration service.

\Drupal\user\UserInterface $user: The user currently attempting to log in.

\Drupal\user\UserDataInterface $user_data: The user data service.

\Symfony\Component\HttpFoundation\Request $request: The current request.

Overrides TfaContextInterface::__construct

File

src/TfaContext.php, line 96

Class

TfaContext
Provide context for the current login attempt.

Namespace

Drupal\tfa

Code

public function __construct(TfaValidationPluginManager $tfa_validation_manager, TfaLoginPluginManager $tfa_plugin_manager, ConfigFactoryInterface $config_factory, UserInterface $user, UserDataInterface $user_data, Request $request) {
  $this->tfaValidationManager = $tfa_validation_manager;
  $this->tfaLoginManager = $tfa_plugin_manager;
  $this->tfaSettings = $config_factory
    ->get('tfa.settings');
  $this->user = $user;
  $this->userData = $user_data;
  $this->request = $request;
  $this->tfaLoginPlugins = $this->tfaLoginManager
    ->getPlugins([
    'uid' => $user
      ->id(),
  ]);

  // If possible, set up an instance of tfaValidationPlugin and the user's
  // list of plugins.
  $this->validationPluginName = $this->tfaSettings
    ->get('default_validation_plugin');
  if (!empty($this->validationPluginName)) {
    $this->tfaValidationPlugin = $this->tfaValidationManager
      ->createInstance($this->validationPluginName, [
      'uid' => $user
        ->id(),
    ]);
    $this->userLoginPlugins = $this->tfaLoginManager
      ->getPlugins([
      'uid' => $user
        ->id(),
    ]);
  }
}