You are here

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

2 calls to Utilities::validate_otp_submit()
MiniorangeSamlCustomerSetup::miniorange_saml_validate_otp_submit in src/Form/MiniorangeSamlCustomerSetup.php
Validate OTP.
miniorange_saml_sp_registration::miniorange_saml_register_popup in src/miniorange_saml_sp_registration.php

File

src/Utilities.php, line 751

Class

Utilities
This file is part of miniOrange SAML plugin.

Namespace

Drupal\miniorange_saml

Code

public static function validate_otp_submit($otp_token, $called_from_popup = false, $payment_plan = NULL) {
  global $base_url;
  $db_config = \Drupal::config('miniorange_saml.settings');
  $db_edit = \Drupal::configFactory()
    ->getEditable('miniorange_saml.settings');
  $username = $db_config
    ->get('miniorange_saml_customer_admin_email');
  $phone = $db_config
    ->get('miniorange_saml_customer_admin_phone');
  $tx_id = $db_config
    ->get('miniorange_saml_tx_id');
  $customer_config = new MiniorangeSAMLCustomer($username, $phone, NULL, $otp_token);
  $validate_otp_response = json_decode($customer_config
    ->validateOtp($tx_id));
  if ($validate_otp_response->status == 'SUCCESS') {
    $db_edit
      ->clear('miniorange_saml_tx_id')
      ->save();
    $password = $db_config
      ->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') {
      $db_edit
        ->set('miniorange_saml_status', 'PLUGIN_CONFIGURATION')
        ->save();
      $db_edit
        ->set('miniorange_saml_customer_admin_email', $username)
        ->save();
      $db_edit
        ->set('miniorange_saml_customer_admin_phone', $phone)
        ->save();
      $db_edit
        ->set('miniorange_saml_customer_admin_token', $create_customer_response->token)
        ->save();
      $db_edit
        ->set('miniorange_saml_customer_id', $create_customer_response->id)
        ->save();
      $db_edit
        ->set('miniorange_saml_customer_api_key', $create_customer_response->apiKey)
        ->save();
      \Drupal::messenger()
        ->addMessage(t('Your account has been created successfully!'));
      if ($called_from_popup == true) {
        $redirect_url = $db_edit
          ->get('redirect_plan_after_registration_' . $payment_plan);
        $redirect_url = str_replace('none', $username, $redirect_url);
      }
      else {
        $redirect_url = $base_url . MiniorangeSAMLConstants::LICENSING_TAB_URL;
      }
      miniorange_saml_sp_registration::miniorange_redirect_successfull($redirect_url);
    }
    else {
      if (trim($create_customer_response->status) == 'INVALID_EMAIL_QUICK_EMAIL') {
        \Drupal::messenger()
          ->addMessage(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>
                Please try again with a valid email.'), 'error');
        $db_edit
          ->set('miniorange_saml_status', '')
          ->save();
        if ($called_from_popup == true) {
          self::saml_back(true);
        }
        else {
          return;
        }
      }
      else {
        \Drupal::messenger()
          ->addMessage(t('There was an error while creating customer. Please try after some time.'), 'error');
        if ($called_from_popup == true) {
          self::saml_back(true);
        }
        else {
          return;
        }
      }
    }
  }
  else {
    if ($called_from_popup == true) {
      miniorange_saml_sp_registration::miniorange_otp(true, false, false);
    }
    else {
      \Drupal::messenger()
        ->addMessage(t('Invalid  OTP'), 'error');
      return;
    }
  }
}