Commit dd7f5fe2 authored by João Ventura's avatar João Ventura Committed by Joao Ventura
Browse files

Issue #3314265 by jcnventura: Unify the plugins

parent c3560e87
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\services\ServiceDefinitionBase;
use Drupal\tfa\TfaValidationPluginManager;
use Drupal\tfa\TfaPluginManager;
use Drupal\user\UserDataInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -30,12 +30,13 @@ use Symfony\Component\Serializer\SerializerInterface;
 */
class GenericValidation extends ServiceDefinitionBase implements ContainerFactoryPluginInterface {
  use DependencySerializationTrait;

  /**
   * Validation plugin manager.
   *
   * @var \Drupal\tfa\TfaValidationPluginManager
   * @var \Drupal\tfa\TfaPluginManager
   */
  protected $tfaValidationManager;
  protected $tfaPluginManager;

  /**
   * The validation plugin object.
@@ -45,9 +46,9 @@ class GenericValidation extends ServiceDefinitionBase implements ContainerFactor
  protected $validationPlugin;

  /**
   * The validation plugin object.
   * User data service.
   *
   * @var \Drupal\tfa\Plugin\TfaValidationInterface
   * @var \Drupal\user\UserDataInterface
   */
  protected $userData;

@@ -62,13 +63,13 @@ class GenericValidation extends ServiceDefinitionBase implements ContainerFactor
   *   The plugin implementation definition.
   * @param \Drupal\user\UserDataInterface $user_data
   *   User data service.
   * @param \Drupal\tfa\TfaValidationPluginManager $tfa_validation_manager
   *   Validation plugin manager.
   * @param \Drupal\tfa\TfaPluginManager $tfa_plugin_manager
   *   Tfa plugin manager.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, UserDataInterface $user_data, TfaValidationPluginManager $tfa_validation_manager) {
  public function __construct(array $configuration, $plugin_id, $plugin_definition, UserDataInterface $user_data, TfaPluginManager $tfa_plugin_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->userData = $user_data;
    $this->tfaValidationManager = $tfa_validation_manager;
    $this->tfaPluginManager = $tfa_plugin_manager;
  }

  /**
@@ -80,7 +81,7 @@ class GenericValidation extends ServiceDefinitionBase implements ContainerFactor
      $plugin_id,
      $plugin_definition,
      $container->get('user.data'),
      $container->get('plugin.manager.tfa.validation')
      $container->get('plugin.manager.tfa')
    );
  }

@@ -103,7 +104,7 @@ class GenericValidation extends ServiceDefinitionBase implements ContainerFactor
    $plugin_id = $request->get('plugin_id');

    if ($uid && $code && $plugin_id) {
      $this->validationPlugin = $this->tfaValidationManager->createInstance($plugin_id, ['uid' => $uid]);
      $this->validationPlugin = $this->tfaPluginManager->createInstance($plugin_id, ['uid' => $uid]);
      // @todo validateRequest is not part of TfaValidationInterface.
      $valid = $this->validationPlugin->validateRequest($code);
      if ($this->validationPlugin->isAlreadyAccepted()) {
+4 −4
Original line number Diff line number Diff line
@@ -5,11 +5,11 @@ namespace Drupal\tfa\Annotation;
use Drupal\Component\Annotation\Plugin;

/**
 * Defines a TFA Setup annotation object.
 * Defines a TFA annotation object.
 *
 * @Annotation
 */
class TfaSetup extends Plugin {
class Tfa extends Plugin {

  /**
   * The plugin ID.
@@ -19,7 +19,7 @@ class TfaSetup extends Plugin {
  public $id;

  /**
   * The human-readable name of the Tfa setup.
   * The human-readable name of the plugin.
   *
   * @var \Drupal\Core\Annotation\Translation
   *
@@ -28,7 +28,7 @@ class TfaSetup extends Plugin {
  public $title;

  /**
   * The description shown to users.
   * The description of the plugin.
   *
   * @var \Drupal\Core\Annotation\Translation
   *

src/Annotation/TfaLogin.php

deleted100644 → 0
+0 −46
Original line number Diff line number Diff line
<?php

namespace Drupal\tfa\Annotation;

use Drupal\Component\Annotation\Plugin;

/**
 * Defines a TFA Login annotation object.
 *
 * @Annotation
 */
class TfaLogin extends Plugin {

  /**
   * The plugin ID.
   *
   * @var string
   */
  public $id;

  /**
   * The human-readable name of the Tfa login.
   *
   * @var \Drupal\Core\Annotation\Translation
   *
   * @ingroup plugin_translatable
   */
  public $title;

  /**
   * The description shown to users.
   *
   * @var \Drupal\Core\Annotation\Translation
   *
   * @ingroup plugin_translatable
   */
  public $description;

  /**
   * Plugin ID for user-specific setup plugin for this login plugin.
   *
   * @var string
   */
  public $setupPluginId;

}

src/Annotation/TfaSend.php

deleted100644 → 0
+0 −46
Original line number Diff line number Diff line
<?php

namespace Drupal\tfa\Annotation;

use Drupal\Component\Annotation\Plugin;

/**
 * Defines a TFA Send annotation object.
 *
 * @Annotation
 */
class TfaSend extends Plugin {

  /**
   * The plugin ID.
   *
   * @var string
   */
  public $id;

  /**
   * The human-readable name of the Tfa send.
   *
   * @var \Drupal\Core\Annotation\Translation
   *
   * @ingroup plugin_translatable
   */
  public $title;

  /**
   * The description shown to users.
   *
   * @var \Drupal\Core\Annotation\Translation
   *
   * @ingroup plugin_translatable
   */
  public $description;

  /**
   * Plugin ID for user-specific setup plugin for this send plugin.
   *
   * @var string
   */
  public $setupPluginId;

}

src/Annotation/TfaValidation.php

deleted100644 → 0
+0 −46
Original line number Diff line number Diff line
<?php

namespace Drupal\tfa\Annotation;

use Drupal\Component\Annotation\Plugin;

/**
 * Defines a TFA Validation annotation object.
 *
 * @Annotation
 */
class TfaValidation extends Plugin {

  /**
   * The plugin ID.
   *
   * @var string
   */
  public $id;

  /**
   * The human-readable name of the Tfa validation.
   *
   * @var \Drupal\Core\Annotation\Translation
   *
   * @ingroup plugin_translatable
   */
  public $title;

  /**
   * The description shown to users.
   *
   * @var \Drupal\Core\Annotation\Translation
   *
   * @ingroup plugin_translatable
   */
  public $description;

  /**
   * Plugin ID for user-specific setup plugin for this validation plugin.
   *
   * @var string
   */
  public $setupPluginId;

}
Loading