public function test_otp_over_email::buildForm in Google Authenticator / 2 Factor Authentication - 2FA 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ test_otp_over_email.php, line 24 - OTP Over Email(test) functions.
Class
- test_otp_over_email
- Menu callback for testing OTP Over Email.
Namespace
Drupal\miniorange_2fa\FormCode
public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
$form['markup_top_2'] = array(
'#markup' => '<div class="mo_saml_table_layout_1"><div class="mo_saml_table_layout mo_saml_container">',
);
$form['markup_library'] = array(
'#attached' => array(
'library' => array(
"miniorange_2fa/miniorange_2fa.admin",
"miniorange_2fa/miniorange_2fa.license",
),
),
);
global $base_url;
$url = $base_url . '/admin/config/people/miniorange_2fa/setup_twofactor';
$user = User::load(\Drupal::currentUser()
->id());
$user_id = $user
->id();
$custom_attribute = MoAuthUtilities::get_users_custom_attribute($user_id);
$user_email = $custom_attribute[0]->miniorange_registered_email;
$user_phone = \Drupal::config('miniorange_2fa.settings')
->get('mo_phone');
$authTypeCode = AuthenticationType::$OTP_OVER_EMAIL['code'];
$txId_Value = \Drupal::config('miniorange_2fa.settings')
->get('txId_Value');
if ($txId_Value == 'EMPTY_VALUE') {
$messageHeader = 'An OTP has been sent to <strong>' . $user_email . '</strong>. Please enter it here to complete the test.';
$customer = new MiniorangeCustomerProfile();
$miniorange_user = new MiniorangeUser($customer
->getCustomerID(), NULL, $user_phone, NULL, $authTypeCode, $user_email);
$auth_api_handler = new AuthenticationAPIHandler($customer
->getCustomerID(), $customer
->getAPIKey());
$response = $auth_api_handler
->challenge($miniorange_user);
if (isset($response->status) && $response->status != 'SUCCESS') {
$message = 'An error occured while sending passcode. <em>(' . $response->message . ')</em>';
MoAuthUtilities::show_error_or_success_message($message, 'error');
}
else {
\Drupal::messenger()
->addMessage(t($messageHeader), 'status');
}
//Store txId
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->set('txId_Value', $response->txId)
->save();
}
$form['header']['#markup'] = '<div class="mo2f-setup-header"><div class="mo2f-setup-header-top-left">Test OTP Over Email</div></div>';
$form['mo_auth_otpover_email_token'] = array(
'#type' => 'textfield',
'#maxlength' => 6,
'#attributes' => array(
'placeholder' => t('Enter passcode.'),
'class' => array(
'mo2f-textbox',
'mo2f-textbox-otp',
),
'style' => 'width:200px',
'autofocus' => 'true',
),
);
$form['actions_form_submit'] = array(
'#type' => 'submit',
'#value' => t('Verify'),
);
$form['actions_form_cancel'] = array(
'#markup' => '<span> </span><a href="' . $url . ' "> Cancel Test</a>',
);
$form['main_layout_div_end'] = array(
'#markup' => '<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></div>',
);
MoAuthUtilities::AddsupportTab($form, $form_state);
return $form;
}