class TfaTestSend in Two-factor Authentication (TFA) 7.2
Class TfaTestSend.
Hierarchy
- class \TfaBasePlugin
- class \TfaTestSend implements TfaSendPluginInterface, TfaValidationPluginInterface
Expanded class hierarchy of TfaTestSend
1 string reference to 'TfaTestSend'
- tfa_test_tfa_api in tests/
tfa_test.module - Implements hook_tfa_api().
File
- tests/
includes/ tfa_test.send.inc, line 11 - Tests for the TfaSendPluginInterface.
View source
class TfaTestSend extends TfaBasePlugin implements TfaValidationPluginInterface, TfaSendPluginInterface {
/**
* Constructor.
*/
public function __construct(array $context = array()) {
parent::__construct($context);
$this->code = variable_get('tfa_test_code', 'TEST');
}
/**
* {@inheritdoc}
*/
public function ready() {
return variable_get('tfa_test_is_ready', TRUE);
}
/**
* {@inheritdoc}
*/
public function getForm(array $form, array &$form_state) {
$form['code'] = array(
'#type' => 'textfield',
'#title' => t('Enter sent code'),
'#required' => TRUE,
);
$form['actions']['login'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
$form['actions']['resend'] = array(
'#type' => 'submit',
'#value' => t('Resend'),
'#submit' => array(
'tfa_form_submit',
),
'#limit_validation_errors' => array(),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array $form, array &$form_state) {
if (!parent::validate($form_state['values']['code'])) {
$this->errorMessages['code'] = t('Invalid sent code');
return FALSE;
}
else {
return TRUE;
}
}
/**
* Check resend flood.
*
* @param int $window
* Number of seconds in the time window for this event.
*
* @return bool
* TRUE if resend flood was not reached, FALSE otherwise.
*/
public function floodIsAllowed($window) {
if (!flood_is_allowed('tfa_test_resend', variable_get('tfa_test_resend_threshold', 6), $window, $this->context['uid'])) {
$this->errorMessages['code'] = t('Resend flood hit');
return FALSE;
}
return TRUE;
}
/**
* {@inheritdoc}
*/
public function submitForm(array $form, array &$form_state) {
if ($form_state['values']['op'] === $form_state['values']['resend']) {
// Register resend event for flood protection.
flood_register_event('tfa_test_resend', 3600, $this->context['uid']);
// Support causing send error.
if (!variable_get('tfa_test_send_begin', TRUE)) {
drupal_set_message(t('Error during resend'), 'error');
}
else {
drupal_set_message(t('Code resent'));
}
return FALSE;
}
else {
return parent::submitForm($form, $form_state);
}
}
/**
* {@inheritdoc}
*/
public function begin() {
// Clear resend flood.
flood_clear_event('tfa_test_resend');
// Variable used by TfaTestCase::testSendError().
if (!variable_get('tfa_test_send_begin', TRUE)) {
drupal_set_message(t('Error during send'), 'error');
}
// A real plugin might send the code to the user.
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TfaBasePlugin:: |
protected | property | TFA code. | |
TfaBasePlugin:: |
protected | property | Code Length. | |
TfaBasePlugin:: |
protected | property | Context of current TFA process. | |
TfaBasePlugin:: |
protected | property | Encryption key. | |
TfaBasePlugin:: |
protected | property | Error messages. | |
TfaBasePlugin:: |
protected | property | Code is valid. | |
TfaBasePlugin:: |
constant | |||
TfaBasePlugin:: |
protected | function | Decrypt a encrypted string. | |
TfaBasePlugin:: |
protected | function | Decrypt using the deprecated Mcrypt extension. | |
TfaBasePlugin:: |
protected | function | Use OpenSSL to decrypt data that was originally encrypted with Mcrypt. | |
TfaBasePlugin:: |
protected | function | Encrypt a plaintext string. | |
TfaBasePlugin:: |
protected | function | Encrypt using the deprecated Mcrypt extension. | |
TfaBasePlugin:: |
protected | function | Generate a random string of characters of length $this->codeLength. | |
TfaBasePlugin:: |
public | function | Get error messages suitable for form_set_error(). | |
TfaBasePlugin:: |
private | function | A timing safe equals comparison. | |
TfaBasePlugin:: |
protected | function | Validate code. | |
TfaTestSend:: |
public | function |
TFA process begin. Overrides TfaSendPluginInterface:: |
|
TfaTestSend:: |
public | function | Check resend flood. | |
TfaTestSend:: |
public | function |
Get TFA process form from plugin. Overrides TfaValidationPluginInterface:: |
|
TfaTestSend:: |
public | function |
Determine if the plugin can run for the current TFA context. Overrides TfaBasePlugin:: |
|
TfaTestSend:: |
public | function |
Submit form. Overrides TfaBasePlugin:: |
|
TfaTestSend:: |
public | function |
Validate form. Overrides TfaValidationPluginInterface:: |
|
TfaTestSend:: |
public | function |
Constructor. Overrides TfaBasePlugin:: |