Created
November 30, 2023 12:08
-
-
Save simesy/7bfbca281cf1e1594f20e2d233b2186e to your computer and use it in GitHub Desktop.
ECA Condition - TFA is Setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\my_module\Plugin\ECA\Condition; | |
use Drupal\eca\Plugin\ECA\Condition\ConditionBase; | |
use Drupal\tfa\TfaLoginContextTrait; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
/** | |
* ECA TFA Condition. | |
* | |
* @EcaCondition( | |
* id = "my_tfa_setup", | |
* label = @Translation("TFA Status of the current user"), | |
* description = @Translation("Checks, whether the user has setup TFA properly.") | |
* ) | |
*/ | |
class TfaStatus extends ConditionBase { | |
use TfaLoginContextTrait; | |
/** | |
* Validation plugin manager. | |
* | |
* @var \Drupal\tfa\TfaValidationPluginManager | |
*/ | |
protected $tfaValidationManager; | |
/** | |
* Tfa settings config object. | |
* | |
* @var \Drupal\Core\Config\ImmutableConfig | |
*/ | |
protected $tfaSettings; | |
/** | |
* {@inheritdoc} | |
*/ | |
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): ConditionBase { | |
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); | |
$instance->tfaValidationManager = $container->get('plugin.manager.tfa.validation'); | |
$instance->tfaSettings = $container->get('config.factory')->get('tfa.settings'); | |
return $instance; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function evaluate(): bool { | |
$account = $this->entityTypeManager->getStorage('user')->load($this->currentUser->id()); | |
$this->setUser($account); | |
$result = $this->isReady(); | |
return $this->negationCheck($result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment