You are here

function miniorange_saml_resend_otp in Google Authenticator / 2 Factor Authentication - 2FA 7

1 string reference to 'miniorange_saml_resend_otp'
mo_auth_configure_otp_over_sms_and_email in ./configure_otp_over_sms_and_email.inc

File

./configure_otp_over_sms_and_email.inc, line 116

Code

function miniorange_saml_resend_otp($form, &$form_state) {
  $form_state['rebuild'] = TRUE;
  if (empty($form['miniorange_phone']['#value'])) {
    drupal_set_message(t('Please enter phone number to proceed.'), 'warning');
    return;
  }
  global $base_url, $user;
  $customer = new MiniorangeCustomerProfile();
  $custID = $customer
    ->getCustomerID();
  $api_key = $customer
    ->getAPIKey();
  $user = user_load($user->uid);
  $user_email = $user->miniorange_registered_email[LANGUAGE_NONE][0]['value'];
  $phone_number = $form['miniorange_phone']['#value'];
  $currentMethod = "OTP_OVER_SMS_AND_EMAIL";
  $customer_config = new MiniorangeCustomerSetup($user_email, $phone_number, NULL, NULL);
  $params = array(
    'phone' => $phone_number,
    'email' => $user_email,
  );
  $response = $customer_config
    ->send_otp_token($params, $currentMethod, $custID, $api_key);
  $send_otp_response = json_decode($response);
  if ($send_otp_response->status == 'SUCCESS') {

    // Store txID.
    variable_set('mo_auth_tx_id', $send_otp_response->txId);
    drupal_set_message(t('We have sent an OTP to @phone. Please enter the OTP to verify your phone number.', array(
      '@phone' => $phone_number,
    )));
  }
  elseif ($send_otp_response->status == 'CURL_ERROR') {
    drupal_set_message(t('cURL is not enabled. Please enable cURL'), 'error');
  }
  else {
    drupal_set_message(t($send_otp_response->message), 'error');
  }
}