You are here

public function MobileNumberTfa::__construct in Mobile Number 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/TfaValidation/MobileNumberTfa.php \Drupal\mobile_number\Plugin\TfaValidation\MobileNumberTfa::__construct()

Constructs a new Tfa plugin object.

Parameters

array $configuration: The plugin configuration.

string $plugin_id: The plugin id.

mixed $plugin_definition: The plugin definition.

\Drupal\user\UserDataInterface $user_data: User data object to store user specific information.

\Drupal\encrypt\EncryptionProfileManagerInterface $encryption_profile_manager: Encryption profile manager.

\Drupal\encrypt\EncryptServiceInterface $encrypt_service: Encryption service.

Overrides TfaBasePlugin::__construct

File

src/Plugin/TfaValidation/MobileNumberTfa.php, line 52
MobileNumberTfa.php

Class

MobileNumberTfa
Class MobileNumberTfa is a validation and sending plugin for TFA.

Namespace

Drupal\mobile_number\Plugin\TfaValidation

Code

public function __construct(array $configuration, $plugin_id, $plugin_definition, UserDataInterface $user_data, EncryptionProfileManagerInterface $encryption_profile_manager, EncryptServiceInterface $encrypt_service, MessengerInterface $messenger) {
  parent::__construct($configuration, $plugin_id, $plugin_definition, $user_data, $encryption_profile_manager, $encrypt_service);
  $this->mobileNumberUtil = \Drupal::service('mobile_number.util');
  $this->messenger = $messenger;
  if (!empty($context['validate_context']) && !empty($context['validate_context']['code'])) {
    $this->code = $context['validate_context']['code'];
  }
  if (!empty($context['validate_context']) && !empty($context['validate_context']['verification_token'])) {
    $this->verificationToken = $context['validate_context']['verification_token'];
  }
  $this->codeLength = 4;
  if ($m = $this->mobileNumberUtil
    ->tfaAccountNumber($context['uid'])) {
    try {
      $this->mobileNumber = $this->mobileNumberUtil
        ->testMobileNumber($m);
    } catch (MobileNumberException $e) {
      throw new Exception("Two factor authentication failed: \n" . $e
        ->getMessage(), $e
        ->getCode());
    }
  }
}