You are here

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

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

File

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

Class

MoAuthCustomerSetup
Customer setup form().

Namespace

Drupal\miniorange_2fa\Form

Code

function mo_auth_resend_otp(&$form, $form_state) {
  \Drupal::configFactory()
    ->getEditable('miniorange_2fa.settings')
    ->clear('mo_auth_tx_id')
    ->save();
  $username = \Drupal::config('miniorange_2fa.settings')
    ->get('mo_auth_customer_admin_email');
  $phone = \Drupal::config('miniorange_2fa.settings')
    ->get('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.
    \Drupal::configFactory()
      ->getEditable('miniorange_2fa.settings')
      ->set('mo_auth_tx_id', $send_otp_response->txId)
      ->save();
    \Drupal::configFactory()
      ->getEditable('miniorange_2fa.settings')
      ->set('mo_auth_status', 'VALIDATE_OTP')
      ->save();
    \Drupal::messenger()
      ->addStatus(t('We have sent an OTP to <strong>@username</strong>. Please enter the OTP to verify your email.', array(
      '@username' => $username,
    )));
  }
}