You are here

function miniorange_2fa_inline_registration::mo_auth_get_qrcode_authentication_form in Google Authenticator / 2 Factor Authentication - 2FA 8

Same name and namespace in other branches
  1. 8.2 src/Form/miniorange_2fa_inline_registration.php \Drupal\miniorange_2fa\form\miniorange_2fa_inline_registration::mo_auth_get_qrcode_authentication_form()
1 call to miniorange_2fa_inline_registration::mo_auth_get_qrcode_authentication_form()
miniorange_2fa_inline_registration::mo_auth_inline_registration_page_four in src/Form/miniorange_2fa_inline_registration.php

File

src/Form/miniorange_2fa_inline_registration.php, line 874

Class

miniorange_2fa_inline_registration

Namespace

Drupal\miniorange_2fa\form

Code

function mo_auth_get_qrcode_authentication_form(array $form, \Drupal\Core\Form\FormStateInterface $form_state, $success_form) {
  global $base_url;
  $storage = $form_state
    ->getStorage();
  $email = $storage['page_one_values']['mo_auth_user_email'];
  $method = $storage['page_three_values']['mo_auth_method'];
  $configureMessage = 'Configure QR Code Authentication';
  if ($method == AuthenticationType::$SOFT_TOKEN['code']) {
    $configureMessage = 'Configure Soft Token';
  }
  elseif ($method == AuthenticationType::$PUSH_NOTIFICATIONS['code']) {
    $configureMessage = 'Configure Push Notification';
  }
  $customer = new MiniorangeCustomerProfile();
  $auth_api_handler = new AuthenticationAPIHandler($customer
    ->getCustomerID(), $customer
    ->getAPIKey());
  $miniorange_user = new MiniorangeUser($customer
    ->getCustomerID(), $email, NULL, NULL, NULL);
  $response = $auth_api_handler
    ->register($miniorange_user, AuthenticationType::$QR_CODE['code'], NULL, NULL, NULL);
  if ($response->status == 'IN_PROGRESS') {
    $page = [
      'page_four_values' => [
        'qrcode_response' => $response,
      ],
      'page_three_values' => $storage['page_three_values'],
      'page_two_values' => $storage['page_two_values'],
      'page_one_values' => $storage['page_one_values'],
    ];
    $form_state
      ->setStorage($page);
    $qrCode = $response->qrCode;
    $image = new FormattableMarkup('<img src="data:image/jpg;base64, ' . $qrCode . '"/>', [
      ':src' => $qrCode,
    ]);
    $iPhoneAppLink = file_create_url($base_url . '/' . drupal_get_path('module', 'miniorange_2fa') . '/includes/images/iphone-google-authenticator-app-link.png');
    $androidAppLink = file_create_url($base_url . '/' . drupal_get_path('module', 'miniorange_2fa') . '/includes/images/android-google-authenticator-app-link.png');
    $form['actions_31'] = array(
      '#markup' => '<div class="mo2f-modal">
              <div class="mo2f-modal-content">
                <div class="mo2f-modal-container mo2f-modal-header">' . $configureMessage . ' (Step 4/5)</div>
                <div class="mo2f-modal-container">',
    );
    $form['actions_32'] = array(
      '#markup' => '<div><div class="mo2f-info"><b>Step 1:</b> Download and install the miniOrange Authenticator app</div>
				<div class="mo2f-text-center" style="display:inline-block;width:60%;text-align:center">
				  <a target="_blank" href="https://itunes.apple.com/us/app/miniorange-authenticator/id796303566?ls=1"><img src="' . $iPhoneAppLink . '"></a>
				</div>
				<div class="mo2f-text-center" style="display:inline-block">
				  <a target="_blank" href="https://play.google.com/store/apps/details?id=com.miniorange.authbeta"><img src="' . $androidAppLink . '"></a>
				</div>
				</div>',
    );
    $form['actions_33'] = array(
      '#markup' => '<div><div class="mo2f-info"><b>Step 2:</b> Scan the QR Code from miniOrange Authenticator app</div>
                                  <div class="mo2f-info"><b>Note:</b> Once you scan the QR code, page will get automatically submitted (Dont refresh the page).</div>
  			                      <div class="mo2f-info mo2f-text-center">',
    );
    $form['actions_qrcode_miniOrange'] = array(
      '#markup' => $image,
    );
    $form['actions_34'] = array(
      '#markup' => '</div></div>',
    );
    $sufix = '</div><div class="mo2f-modal-container mo2f-modal-footer">';
    $form['txId'] = array(
      '#type' => 'hidden',
      '#value' => $response->txId,
      '#suffix' => $sufix,
    );
    $form['url'] = array(
      '#type' => 'hidden',
      '#value' => MoAuthConstants::$AUTH_REGISTRATION_STATUS_API,
    );
    $form['actions'] = array(
      '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
      '#attributes' => array(
        'class' => array(
          'hidebutton',
        ),
      ),
      '#submit' => array(
        '::handle_page_four_submit',
      ),
    );
    global $base_url;
    $url = $base_url . '/user/login';
    $form['cancel_button'] = array(
      '#markup' => '<a href="' . $url . '">Cancel</a>',
    );
  }
  return $form;
}