class TfaTestValidationPluginSetupPlugin in Two-factor Authentication (TFA) 8
TFA Test Validation Plugin Setup Plugin.
@package Drupal\tfa_test_plugins
Plugin annotation
@TfaSetup(
id = "tfa_test_plugins_validation_setup",
label = @Translation("TFA Test Validation Plugin Setup"),
description = @Translation("TFA Test Validation Plugin Setup Plugin"),
helpLinks = {},
setupMessages = {}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\tfa\Plugin\TfaBasePlugin uses DependencySerializationTrait, TfaDataTrait
- class \Drupal\tfa_test_plugins\Plugin\TfaSetup\TfaTestValidationPluginSetupPlugin implements TfaSetupInterface uses StringTranslationTrait
- class \Drupal\tfa\Plugin\TfaBasePlugin uses DependencySerializationTrait, TfaDataTrait
Expanded class hierarchy of TfaTestValidationPluginSetupPlugin
File
- tests/
modules/ tfa_test_plugins/ src/ Plugin/ TfaSetup/ TfaTestValidationPluginSetupPlugin.php, line 25
Namespace
Drupal\tfa_test_plugins\Plugin\TfaSetupView source
class TfaTestValidationPluginSetupPlugin extends TfaBasePlugin implements TfaSetupInterface {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function ready() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getSetupForm(array $form, FormStateInterface $form_state) {
$form['expected_field'] = [
'#type' => 'textfield',
'#title' => $this
->t('Expected field'),
'#required' => TRUE,
];
$form['actions']['#type'] = 'actions';
$form['actions']['login'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => $this
->t('Verify and save'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateSetupForm(array $form, FormStateInterface $form_state) {
$expected_value = $form_state
->getValue('expected_field');
if (empty($expected_value)) {
$form_state
->setError($form['expected_field'], $this
->t('Missing expected value.'));
return FALSE;
}
return TRUE;
}
/**
* {@inheritdoc}
*/
public function submitSetupForm(array $form, FormStateInterface $form_state) {
$encrypted = $this
->encrypt($form_state
->getValue('expected_field'));
$record = [
'test_data' => [
'expected_field' => base64_encode($encrypted),
],
];
$this
->setUserData($this->pluginDefinition['id'], $record, $this->uid, $this->userData);
return TRUE;
}
/**
* Get and decode the data expected during setup.
*
* @return null|string
* The string if found, otherwise NULL;
*
* @throws \Drupal\encrypt\Exception\EncryptionMethodCanNotDecryptException
* @throws \Drupal\encrypt\Exception\EncryptException
*/
public function getExpectedFieldData() {
$data = $this
->getUserData($this->pluginDefinition['id'], 'test_data', $this->uid, $this->userData);
if (!empty($data['expected_field'])) {
return $this
->decrypt(base64_decode($data['expected_field']));
}
return NULL;
}
/**
* {@inheritdoc}
*/
public function getHelpLinks() {
return [];
}
/**
* {@inheritdoc}
*/
public function getSetupMessages() {
return [];
}
/**
* {@inheritdoc}
*/
public function getOverview(array $params) {
return [
'heading' => [
'#type' => 'html_tag',
'#tag' => 'h2',
'#value' => $this
->t('TFA application'),
],
'link' => [
'#theme' => 'links',
'#links' => [
'admin' => [
'title' => !$params['enabled'] ? $this
->t('Set up application') : $this
->t('Reset application'),
'url' => Url::fromRoute('tfa.validation.setup', [
'user' => $params['account']
->id(),
'method' => $params['plugin_id'],
]),
],
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TfaBasePlugin:: |
protected | property | Whether the code has been used before. | |
TfaBasePlugin:: |
protected | property | The user submitted code to be validated. | |
TfaBasePlugin:: |
protected | property | The allowed code length. | |
TfaBasePlugin:: |
protected | property | Encryption profile. | |
TfaBasePlugin:: |
protected | property | Encryption service. | |
TfaBasePlugin:: |
protected | property | The error for the current validation. | |
TfaBasePlugin:: |
protected | property | Whether the validation succeeded or not. | |
TfaBasePlugin:: |
protected | property | The user id. | |
TfaBasePlugin:: |
protected | property | Provides the user data service object. | |
TfaBasePlugin:: |
protected | function | Whether code has already been used. | |
TfaBasePlugin:: |
protected | function | Decrypt a encrypted string. | |
TfaBasePlugin:: |
protected | function | Encrypt a plaintext string. | |
TfaBasePlugin:: |
public | function | Get error messages suitable for form_set_error(). | |
TfaBasePlugin:: |
public | function | Get the plugin label. | |
TfaBasePlugin:: |
protected | function | Store validated code to prevent replay attack. | |
TfaBasePlugin:: |
public | function | Submit form. | 1 |
TfaBasePlugin:: |
protected | function | Validate code. | 1 |
TfaBasePlugin:: |
public | function |
Constructs a new Tfa plugin object. Overrides PluginBase:: |
2 |
TfaDataTrait:: |
protected | function | Deletes data stored for the current validated user account. | |
TfaDataTrait:: |
protected | function | Returns data stored for the current validated user account. | |
TfaDataTrait:: |
protected | function | Store user specific information. | |
TfaDataTrait:: |
protected | function | Get TFA data for an account. | |
TfaDataTrait:: |
public | function | Save TFA data for an account. | |
TfaTestValidationPluginSetupPlugin:: |
public | function | Get and decode the data expected during setup. | |
TfaTestValidationPluginSetupPlugin:: |
public | function |
Returns a list of links containing helpful information for plugin use. Overrides TfaSetupInterface:: |
|
TfaTestValidationPluginSetupPlugin:: |
public | function |
Plugin overview page. Overrides TfaSetupInterface:: |
|
TfaTestValidationPluginSetupPlugin:: |
public | function |
Get the setup form for the validation method. Overrides TfaSetupInterface:: |
|
TfaTestValidationPluginSetupPlugin:: |
public | function |
Returns a list of messages for plugin step. Overrides TfaSetupInterface:: |
|
TfaTestValidationPluginSetupPlugin:: |
public | function |
Determine if the plugin can run for the current TFA context. Overrides TfaBasePlugin:: |
|
TfaTestValidationPluginSetupPlugin:: |
public | function |
Submit the setup form. Overrides TfaSetupInterface:: |
|
TfaTestValidationPluginSetupPlugin:: |
public | function |
Validate the setup data. Overrides TfaSetupInterface:: |