You are here

public static function Utilities::validate_otp_submit in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 7

2 calls to Utilities::validate_otp_submit()
miniorange_saml_registration in ./miniorange_saml_registration.php
miniorange_saml_validate_otp_submit in ./miniorange_saml_customer_setup.inc
Validate OTP.

File

includes/Utilities.php, line 409

Class

Utilities
This file is part of miniOrange SAML plugin.

Code

public static function validate_otp_submit($otp_token, $called_from_popup = false, $payment_plan = NULL) {
  $username = variable_get('miniorange_saml_customer_admin_email', NULL);
  $phone = variable_get('miniorange_saml_customer_admin_phone', NULL);
  $tx_id = variable_get('miniorange_saml_tx_id', NULL);
  $customer_config = new MiniorangeSAMLCustomer($username, $phone, NULL, $otp_token);

  // Validate OTP.
  $validate_otp_response = json_decode($customer_config
    ->validateOtp($tx_id));
  if ($validate_otp_response->status == 'SUCCESS') {

    // OTP Validated. Show Configuration page.
    variable_del('miniorange_saml_tx_id');

    // OTP Validated. Create customer.
    $password = variable_get('miniorange_saml_customer_admin_password', '');
    $customer_config = new MiniorangeSAMLCustomer($username, $phone, $password, NULL);
    $create_customer_response = json_decode($customer_config
      ->createCustomer());
    if ($create_customer_response->status == 'SUCCESS') {

      // Customer created.
      variable_set('miniorange_saml_status', 'PLUGIN_CONFIGURATION');
      variable_set('miniorange_saml_customer_admin_email', $username);
      variable_set('miniorange_saml_customer_admin_phone', $phone);
      variable_set('miniorange_saml_customer_admin_token', $create_customer_response->token);
      variable_set('miniorange_saml_customer_id', $create_customer_response->id);
      variable_set('miniorange_saml_customer_api_key', $create_customer_response->apiKey);
      if ($called_from_popup == true) {
        $payment_page_url = variable_get('redirect_plan_after_registration_' . $payment_plan, '');
        $payment_page_url = str_replace('none', $username, $payment_page_url);
        miniorange_redirect_successful($payment_page_url);
      }
      else {
        drupal_set_message(t('Account created successfully. Now you can upgrade to the standard, premium and enterprise versions of the modules.'));
        self::redirect_to_licensing();
      }
    }
    else {
      if (trim($create_customer_response->status) == 'INVALID_EMAIL_QUICK_EMAIL') {
        if ($called_from_popup == true) {
          variable_set('miniorange_saml_status', 'CUSTOMER_SETUP');
          register_data(false, false, true);
        }
        else {
          drupal_set_message(t('There was an error creating an account for you. You may have entered an invalid Email-Id
                            <strong>(We discourage the use of disposable emails) </strong>
                            <br>Please try again with a valid email.'), 'error');
        }
      }
      else {
        if ($called_from_popup == true) {
          self::redirect_to_licensing();
        }
        else {
          drupal_set_message(t('Error creating an account.'), 'error');
          return;
        }
      }
    }
  }
  else {
    if ($called_from_popup == true) {
      miniorange_otp(true, false, false);
    }
    else {
      drupal_set_message(t('You have entered the incorrect OTP. Please try again.'), 'error');
    }
  }
}