You are here

function MoAuthCustomerSetup::mo_auth_resend_otp in Google Authenticator / 2 Factor Authentication - 2FA 8.2

Same name and namespace in other branches
  1. 8 src/Form/MoAuthCustomerSetup.php \Drupal\miniorange_2fa\Form\MoAuthCustomerSetup::mo_auth_resend_otp()

File

src/Form/MoAuthCustomerSetup.php, line 514
Contains form for customer setup.

Class

MoAuthCustomerSetup
Customer setup form().

Namespace

Drupal\miniorange_2fa\Form

Code

function mo_auth_resend_otp(&$form, $form_state) {
  $utilities = new MoAuthUtilities();
  $utilities
    ->miniOrange_set_get_configurations(array(
    'mo_auth_tx_id',
  ), 'CLEAR');
  $variables = array(
    'mo_auth_customer_admin_email',
    'mo_auth_customer_admin_phone',
  );
  $mo_db_values = $utilities
    ->miniOrange_set_get_configurations($variables, 'GET');
  $username = $mo_db_values['mo_auth_customer_admin_email'];
  $phone = $mo_db_values['mo_auth_customer_admin_phone'];
  $customer_config = new MiniorangeCustomerSetup($username, $phone, NULL, NULL);
  $send_otp_response = $customer_config
    ->sendOtp();
  if ($send_otp_response->status == 'SUCCESS') {

    // Store txID.
    $variables_2 = array(
      'mo_auth_tx_id' => $send_otp_response->txId,
      'mo_auth_status' => 'VALIDATE_OTP',
    );
    $utilities
      ->miniOrange_set_get_configurations($variables_2, 'SET');
    \Drupal::messenger()
      ->addStatus(t('We have sent an OTP to <strong>@username</strong>. Please enter the OTP to verify your email.', array(
      '@username' => $username,
    )));
    return;
  }
  elseif ($send_otp_response->status == 'CURL_ERROR') {
    \Drupal::messenger()
      ->addError(t('cURL is not enabled. Please enable cURL'));
    return;
  }
}