function miniorange_2fa_inline_registration::mo_auth_get_google_authentication_form in Google Authenticator / 2 Factor Authentication - 2FA 8.2
Same name and namespace in other branches
- 8 src/Form/miniorange_2fa_inline_registration.php \Drupal\miniorange_2fa\form\miniorange_2fa_inline_registration::mo_auth_get_google_authentication_form()
1 call to miniorange_2fa_inline_registration::mo_auth_get_google_authentication_form()
File
- src/
Form/ miniorange_2fa_inline_registration.php, line 881 - Page 1: Select Email address. Page 2: Verify OTP. Page 3: Select Auth Method. Page 4: Configure Auth Method. Page 5: Configure KBA.
Class
- miniorange_2fa_inline_registration
- @file Page 1: Select Email address. Page 2: Verify OTP. Page 3: Select Auth Method. Page 4: Configure Auth Method. Page 5: Configure KBA.
Namespace
Drupal\miniorange_2fa\formCode
function mo_auth_get_google_authentication_form(array $form, FormStateInterface $form_state, $success_status) {
global $base_url;
$storage = $form_state
->getStorage();
$email = $storage['page_one_values']['mo_auth_user_email'];
$method = $storage['page_three_values']['mo_auth_method'];
$configuration_method = t('Google');
if ($method == AuthenticationType::$MICROSOFT_AUTHENTICATOR['code']) {
$configuration_method = t('Microsoft');
}
elseif ($method == AuthenticationType::$AUTHY_AUTHENTICATOR['code']) {
$configuration_method = t('Authy');
}
elseif ($method == AuthenticationType::$LASTPASS_AUTHENTICATOR['code']) {
$configuration_method = t('LastPass');
}
elseif ($method == AuthenticationType::$DUO_AUTHENTICATOR['code']) {
$configuration_method = t('Duo');
}
if (isset($storage['page_four_values']['google_auth_response'])) {
$google_auth_response = $storage['page_four_values']['google_auth_response'];
$qrCode = $google_auth_response->qrCodeData;
$image = new FormattableMarkup('<img class="mo2f_image" src="data:image/jpg;base64, ' . $qrCode . '"/>', [
':src' => $qrCode,
]);
}
else {
$customer = new MiniorangeCustomerProfile();
$auth_api_handler = new AuthenticationAPIHandler($customer
->getCustomerID(), $customer
->getAPIKey());
$miniorange_user = new MiniorangeUser($customer
->getCustomerID(), $email, NULL, NULL, NULL);
$response = $auth_api_handler
->getGoogleAuthSecret($miniorange_user);
if ($response->status == 'SUCCESS') {
$page = [
'page_four_values' => [
'google_auth_response' => $response,
],
'page_three_values' => $storage['page_three_values'],
'page_two_values' => $storage['page_two_values'],
'page_one_values' => $storage['page_one_values'],
];
$form_state
->setStorage($page);
$qrCode = $response->qrCodeData;
$image = new FormattableMarkup('<img class="mo2f_image" src="data:image/jpg;base64, ' . $qrCode . '"/>', [
':src' => $qrCode,
]);
}
}
$iPhoneAppLink = file_create_url($base_url . '/' . drupal_get_path('module', 'miniorange_2fa') . '/includes/images/iphone-google-authenticator-app-link.png');
$androidAppLink = file_create_url($base_url . '/' . drupal_get_path('module', 'miniorange_2fa') . '/includes/images/android-google-authenticator-app-link.png');
$stepMessage = $this
->is2FAResetRequest($form_state) ? '' : '(Step 4/5)';
$form['actions_21'] = array(
'#markup' => '<div class="mo2f-modal">
<div class="mo2f-modal-content">
<div class="mo2f-modal-container mo2f-modal-header">' . t('Configure ') . $configuration_method . t(' Authenticator ') . $stepMessage . '</div>
<div class="mo2f-modal-container">',
);
if ($success_status === FALSE) {
$message = t('The passcode you have entered is incorrect.');
$form['actions_22'] = array(
'#markup' => '
<div class="mo2f-message mo2f-message-error">' . $message . '</div>',
);
$_SESSION['success_status'] = TRUE;
}
$form['actions_23'] = array(
'#markup' => '<div><div class="mo2f-info"><b class="mo2f_bold">' . t('Step 1:') . '</b> ' . t('Download and install the ') . $configuration_method . ' Authenticator app</div>
<div class="mo2f-text-center" style="display:inline-block;width:60%;text-align:center">
<a target="_blank" href="https://itunes.apple.com/in/app/google-authenticator/id388497605?mt=8"><img class="mo2f_image" src="' . $iPhoneAppLink . '"></a>
</div>
<div class="mo2f-text-center" style="display:inline-block">
<a target="_blank" href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2"><img class="mo2f_image" src="' . $androidAppLink . '"></a>
</div>
</div>',
);
$form['actions_24'] = array(
'#markup' => '<div><div class="mo2f-info"><b class="mo2f_bold">Step 2:</b> Scan the QR Code from ' . $configuration_method . ' Authenticator app</div><div class="mo2f-info mo2f-text-center">',
);
$form['actions_qrcode_google_authenticator'] = array(
'#markup' => $image,
);
$form['actions_25'] = array(
'#markup' => '</div><div class="mo2f-info"><b class="mo2f_bold">Step 3:</b> Enter the passcode generated by ' . $configuration_method . ' Authenticator app</div>',
);
$sufix = '</div><div class="mo2f-modal-container mo2f-modal-footer">';
$form['mo_auth_googleauth_token'] = array(
'#type' => 'textfield',
'#attributes' => array(
'placeholder' => t('Enter the passcode'),
'class' => array(
'mo2f-textbox',
'mo2f-textbox-otp',
),
'autofocus' => 'true',
),
'#maxlength' => 8,
'#suffix' => $sufix,
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['verify'] = array(
'#type' => 'submit',
'#value' => t('Verify and Save'),
'#submit' => array(
'::handle_page_four_submit',
),
'#attributes' => array(
'class' => array(
'mo2f_button',
),
),
);
$form['actions']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#submit' => array(
'::handle_page_cancel',
),
'#attributes' => array(
'class' => array(
'mo2f_button',
),
),
);
return $form;
}