class TfaRecoveryCodeSetup in Two-factor Authentication (TFA) 8
TFA Recovery Code Setup Plugin.
Plugin annotation
@TfaSetup(
id = "tfa_recovery_code_setup",
label = @Translation("TFA Recovery Code Setup"),
description = @Translation("TFA Recovery Code Setup Plugin"),
setupMessages = {
"saved" = @Translation("Recovery codes saved."),
"skipped" = @Translation("Recovery codes not saved.")
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\tfa\Plugin\TfaBasePlugin uses DependencySerializationTrait, TfaDataTrait
- class \Drupal\tfa\Plugin\TfaValidation\TfaRecoveryCode implements ContainerFactoryPluginInterface, TfaValidationInterface uses StringTranslationTrait, TfaRandomTrait
- class \Drupal\tfa\Plugin\TfaSetup\TfaRecoveryCodeSetup implements TfaSetupInterface uses TfaDataTrait
- class \Drupal\tfa\Plugin\TfaValidation\TfaRecoveryCode implements ContainerFactoryPluginInterface, TfaValidationInterface uses StringTranslationTrait, TfaRandomTrait
- class \Drupal\tfa\Plugin\TfaBasePlugin uses DependencySerializationTrait, TfaDataTrait
Expanded class hierarchy of TfaRecoveryCodeSetup
File
- src/
Plugin/ TfaSetup/ TfaRecoveryCodeSetup.php, line 24
Namespace
Drupal\tfa\Plugin\TfaSetupView source
class TfaRecoveryCodeSetup extends TfaRecoveryCode implements TfaSetupInterface {
use TfaDataTrait;
/**
* {@inheritdoc}
*/
public function ready() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getOverview(array $params) {
return [
'heading' => [
'#type' => 'html_tag',
'#tag' => 'h2',
'#value' => $this
->t('Recovery Codes'),
],
'description' => [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $this
->t('Generate one-time use codes for two-factor login. These are generally used to recover your account in case you lose access to another 2nd-factor device.'),
],
'setup' => [
'#theme' => 'links',
'#links' => [
'reset' => [
'title' => !$params['enabled'] ? $this
->t('Generate codes') : $this
->t('Reset codes'),
'url' => Url::fromRoute('tfa.plugin.reset', [
'user' => $params['account']
->id(),
'method' => $params['plugin_id'],
'reset' => 1,
]),
],
],
],
'show_codes' => [
'#theme' => 'links',
'#access' => $params['enabled'],
'#links' => [
'show' => [
'title' => $this
->t('Show codes'),
'url' => Url::fromRoute('tfa.validation.setup', [
'user' => $params['account']
->id(),
'method' => $params['plugin_id'],
]),
],
],
],
];
}
/**
* Get the setup form for the validation method.
*
* @param array $form
* The configuration form array.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param int $reset
* Whether or not the user is resetting the application.
*
* @return array
* Form API array.
*/
public function getSetupForm(array $form, FormStateInterface $form_state, $reset = 0) {
$codes = $this
->getCodes();
// If $reset has a value, we're setting up new codes.
if (!empty($reset)) {
$codes = $this
->generateCodes();
// Make the human friendly.
foreach ($codes as $key => $code) {
$codes[$key] = implode(' ', str_split($code, 3));
}
$form['recovery_codes'] = [
'#type' => 'value',
'#value' => $codes,
];
}
$form['recovery_codes_output'] = [
'#title' => $this
->t('Recovery Codes'),
'#theme' => 'item_list',
'#items' => $codes,
];
$form['description'] = [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $this
->t('Print or copy these codes and store them somewhere safe before continuing.'),
];
if (!empty($reset)) {
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['save'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => $this
->t('Save codes to account'),
];
}
return $form;
}
/**
* {@inheritdoc}
*/
public function validateSetupForm(array $form, FormStateInterface $form_state) {
if (!empty($form_state
->getValue('recovery_codes'))) {
return TRUE;
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function submitSetupForm(array $form, FormStateInterface $form_state) {
$this
->storeCodes($form_state
->getValue('recovery_codes'));
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getHelpLinks() {
return [];
}
/**
* {@inheritdoc}
*/
public function getSetupMessages() {
return $this->pluginDefinition['setupMessages'] ?: [];
}
}
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 |
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. | |
TfaRandomTrait:: |
protected | property | Letters allowed during random string generation. | |
TfaRandomTrait:: |
protected | property | Numbers allowed during random string generation. | |
TfaRandomTrait:: |
protected | function | Generate random characters of the given length and allowable characters. | |
TfaRandomTrait:: |
public | function | Generate a random integer of the given character length. | |
TfaRandomTrait:: |
public | function | Generate a random string of the given character length. | |
TfaRecoveryCode:: |
protected | property | The number of recovery codes to generate. | |
TfaRecoveryCode:: |
public | function | Configuration form for the recovery code plugin. | |
TfaRecoveryCode:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
TfaRecoveryCode:: |
protected | function | Delete existing codes. | |
TfaRecoveryCode:: |
public | function | Generate an array of secure recovery codes. | |
TfaRecoveryCode:: |
public | function | Get unused recovery codes. | |
TfaRecoveryCode:: |
public | function |
Get TFA process form from plugin. Overrides TfaValidationInterface:: |
|
TfaRecoveryCode:: |
public | function | Save recovery codes for current account. | |
TfaRecoveryCode:: |
protected | function |
Validate code. Overrides TfaBasePlugin:: |
|
TfaRecoveryCode:: |
public | function |
Validate form. Overrides TfaValidationInterface:: |
|
TfaRecoveryCode:: |
public | function | Simple validate for web services. | |
TfaRecoveryCode:: |
public | function |
Constructs a new Tfa plugin object. Overrides TfaBasePlugin:: |
|
TfaRecoveryCodeSetup:: |
public | function |
Returns a list of links containing helpful information for plugin use. Overrides TfaSetupInterface:: |
|
TfaRecoveryCodeSetup:: |
public | function |
Plugin overview page. Overrides TfaSetupInterface:: |
|
TfaRecoveryCodeSetup:: |
public | function |
Get the setup form for the validation method. Overrides TfaSetupInterface:: |
|
TfaRecoveryCodeSetup:: |
public | function |
Returns a list of messages for plugin step. Overrides TfaSetupInterface:: |
|
TfaRecoveryCodeSetup:: |
public | function |
Determine if the plugin can run for the current TFA context. Overrides TfaRecoveryCode:: |
|
TfaRecoveryCodeSetup:: |
public | function |
Submit the setup form. Overrides TfaSetupInterface:: |
|
TfaRecoveryCodeSetup:: |
public | function |
Validate the setup data. Overrides TfaSetupInterface:: |