function configure_otp_over_sms::miniorange_saml_resend_otp in Google Authenticator / 2 Factor Authentication - 2FA 8
File
- src/
Form/ configure_otp_over_sms.php, line 138
Class
Namespace
Drupal\miniorange_2fa\formCode
function miniorange_saml_resend_otp(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
global $base_url;
$form_state
->setRebuild();
$customer = new MiniorangeCustomerProfile();
$custID = $customer
->getCustomerID();
$api_key = $customer
->getAPIKey();
$user = User::load(\Drupal::currentUser()
->id());
$user_id = $user
->id();
$utilities = new MoAuthUtilities();
$custom_attribute = $utilities::get_users_custom_attribute($user_id);
$user_email = $custom_attribute[0]->miniorange_registered_email;
$phone_number = str_replace(' ', '', $form['miniorange_phone']['#value']);
if (empty($phone_number)) {
\Drupal::messenger()
->addMessage(t('Please enter phone number first.'), 'error');
return;
}
$currentMethod = "OTP_OVER_SMS";
$customer_config = new MiniorangeCustomerSetup($user_email, $phone_number, NULL, NULL);
$response = $customer_config
->send_otp_token($phone_number, $currentMethod, $custID, $api_key);
$send_otp_response = json_decode($response);
if ($send_otp_response->status == 'SUCCESS') {
// Store txID.
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->set('mo_auth_tx_id', $send_otp_response->txId)
->save();
\Drupal::messenger()
->addStatus(t('We have sent an OTP to <strong>@phone</strong>. Please enter the OTP to verify your phone number.', array(
'@phone' => $phone_number,
)));
}
elseif ($send_otp_response->status == 'CURL_ERROR') {
\Drupal::messenger()
->addMessage(t('cURL is not enabled. Please enable cURL'), 'error');
}
else {
\Drupal::messenger()
->addMessage(t($send_otp_response->message), 'error');
}
}