You are here

function miniorange_2fa_inline_registration::mo_auth_get_otp_over_sms_validate_form in Google Authenticator / 2 Factor Authentication - 2FA 8.2

Same name and namespace in other branches
  1. 8 src/Form/miniorange_2fa_inline_registration.php \Drupal\miniorange_2fa\form\miniorange_2fa_inline_registration::mo_auth_get_otp_over_sms_validate_form()
1 call to miniorange_2fa_inline_registration::mo_auth_get_otp_over_sms_validate_form()
miniorange_2fa_inline_registration::mo_auth_inline_registration_page_four_otp_validate in src/Form/miniorange_2fa_inline_registration.php

File

src/Form/miniorange_2fa_inline_registration.php, line 1348
Page 1: Select Email address. Page 2: Verify OTP. Page 3: Select Auth Method. Page 4: Configure Auth Method. Page 5: Configure KBA.

Class

miniorange_2fa_inline_registration
@file Page 1: Select Email address. Page 2: Verify OTP. Page 3: Select Auth Method. Page 4: Configure Auth Method. Page 5: Configure KBA.

Namespace

Drupal\miniorange_2fa\form

Code

function mo_auth_get_otp_over_sms_validate_form(array $form, FormStateInterface $form_state, $success_status, $message) {
  $storage = $form_state
    ->getStorage();
  $method = $storage['page_three_values']['mo_auth_method'];
  $otp_over_sms = AuthenticationType::$SMS['code'];
  $otp_over_sms_and_email = AuthenticationType::$SMS_AND_EMAIL['code'];
  $otp_over_email = AuthenticationType::$EMAIL['code'];
  $otp_over_phone = AuthenticationType::$OTP_OVER_PHONE['code'];
  $hardware_token = AuthenticationType::$HARDWARE_TOKEN['code'];
  $authmethod = '';
  if ($method == $otp_over_sms) {
    $authmethod = t(AuthenticationType::$SMS['name']);
  }
  elseif ($method == $otp_over_sms_and_email) {
    $authmethod = t(AuthenticationType::$SMS_AND_EMAIL['name']);
  }
  elseif ($method == $otp_over_email) {
    $authmethod = t(AuthenticationType::$OTP_OVER_EMAIL['name']);
  }
  elseif ($method == $otp_over_phone) {
    $authmethod = t(AuthenticationType::$OTP_OVER_PHONE['name']);
  }
  elseif ($method == $hardware_token) {
    $authmethod = t(AuthenticationType::$HARDWARE_TOKEN['name']);
  }
  $email = $storage['page_one_values']['mo_auth_user_email'];
  if ($success_status === TRUE) {
    if ($method == $otp_over_sms) {
      $phone = str_replace(' ', '', $storage['page_four_values']['mo_auth_otpoversms_phone']);
      $message = t('We have sent an OTP to  %phone Enter the OTP received to verify your phone.', array(
        '%phone' => $phone,
      ));
    }
    elseif ($method == $otp_over_sms_and_email) {
      $phone = str_replace(' ', '', $storage['page_four_values']['mo_auth_otpoversms_phone']);
      $message = t('We have sent an OTP to %phone and %email . Enter the OTP received to verify your phone and email.', array(
        '%phone' => $phone,
        '%email' => $email,
      ));
    }
    elseif ($method == $otp_over_email) {
      $message = t('We have sent an OTP to %email . Enter the OTP received to verify your email.', array(
        '%email' => $email,
      ));
    }
    elseif ($method == $otp_over_phone) {
      $phone = str_replace(' ', '', $storage['page_four_values']['mo_auth_otpoversms_phone']);
      $message = t('You will receive a call on %phone shortly, which prompts OTP. Please enter the OTP to verify your phone number.', array(
        '%phone' => $phone,
      ));
    }
    elseif ($method = $hardware_token) {
      $message = t('Please press the key from your Yubikey Hardware device.');
    }
  }
  $message_div_class = $success_status === TRUE ? 'mo2f-message-status' : 'mo2f-message-error';
  $stepMessage = $this
    ->is2FAResetRequest($form_state) ? '' : ' ' . t('(Step 4/5)');
  $prefix = '<div class="mo2f-modal">
              <div class="mo2f-modal-content">
                <div class="mo2f-modal-container mo2f-modal-header">Configure ' . $authmethod . $stepMessage . '</div>
                <div class="mo2f-modal-container"><div class="mo2f-message ' . $message_div_class . '">' . $message . '</div>
                  <div class="mo2f-info">' . t('Enter the passcode:') . '</div>
                <div>';
  $suffix = '</div><div class="mo2f-modal-container mo2f-modal-footer">';
  $form['mo_auth_otpoversms_code'] = array(
    '#type' => 'textfield',
    '#attributes' => array(
      'placeholder' => t('Enter the passcode'),
      'class' => array(
        'mo2f-textbox',
        'mo2f-textbox-otp',
      ),
      'autofocus' => 'true',
    ),
    '#required' => TRUE,
    '#prefix' => $prefix,
    '#suffix' => $suffix,
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['validate'] = array(
    '#type' => 'submit',
    '#value' => t('Validate OTP'),
    '#submit' => array(
      '::handle_page_otp_validate_submit',
    ),
    '#attributes' => array(
      'class' => array(
        'mo2f_button',
      ),
    ),
  );
  $form['actions']['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
    '#limit_validation_errors' => array(),
    '#submit' => array(
      '::handle_page_cancel',
    ),
    '#attributes' => array(
      'class' => array(
        'mo2f_button',
      ),
    ),
  );
  return $form;
}