You are here

function mo_auth_configure_qrcode_authentication in Google Authenticator / 2 Factor Authentication - 2FA 7

1 string reference to 'mo_auth_configure_qrcode_authentication'
mo_auth_menu in ./mo_auth.module
Implements hook_menu().

File

./configure_qrcode_authentication.inc, line 2

Code

function mo_auth_configure_qrcode_authentication($form, &$form_state) {
  global $base_url, $user;
  $user = user_load($user->uid);
  $form['actions'] = array(
    '#type' => 'actions',
  );

  /* To check which method (Soft Token, QR Code, Push Notification') is being configured by user
   * $authTypeCode:- Code of the authentication Type
   * $messageHeader:- Title of the Page
   */
  $query_param = $_GET["q"];
  $url_parts = explode('/', $query_param);
  $authTypeCode = '';
  $messageHeader = '';
  if (in_array("soft-token", $url_parts)) {
    $authTypeCode = AuthenticationType::$SOFT_TOKEN['code'];
    $messageHeader = 'Configure Soft Token';
  }
  elseif (in_array("push-notifications", $url_parts)) {
    $authTypeCode = AuthenticationType::$PUSH_NOTIFICATIONS['code'];
    $messageHeader = 'Configure Push Notifications';
  }
  else {
    $authTypeCode = AuthenticationType::$QR_CODE['code'];
    $messageHeader = 'Configure QR Code Authentication';
  }
  if (array_key_exists('txId', $form_state['input']) === FALSE) {
    $user_email = $user->miniorange_registered_email[LANGUAGE_NONE][0]['value'];
    $customer = new MiniorangeCustomerProfile();
    $miniorange_user = new MiniorangeUser($customer
      ->getCustomerID(), $user_email, NULL, NULL, AuthenticationType::$QR_CODE['code']);
    $auth_api_handler = new AuthenticationAPIHandler($customer
      ->getCustomerID(), $customer
      ->getAPIKey());
    $response = $auth_api_handler
      ->register($miniorange_user, AuthenticationType::$QR_CODE['code'], NULL, NULL, NULL);
    $qrCode = $response->qrCode;
    $form['header']['#markup'] = '<div class="mo2f-setup-header"><div class="mo2f-setup-header-top-left">' . $messageHeader . '</div></div>' . mo_auth_create_form($base_url, $qrCode);
    $form['#attached']['js'][] = array(
      'data' => array(
        'mo_authentication' => array(
          'txId' => $response->txId,
          'url' => MoAuthConstants::getBaseUrl() . MoAuthConstants::$AUTH_REGISTRATION_STATUS_API,
        ),
      ),
      'type' => 'setting',
    );
    $form['txId'] = array(
      '#type' => 'hidden',
      '#value' => $response->txId,
    );
    $form['authTypeCode'] = array(
      '#type' => 'hidden',
      '#value' => $authTypeCode,
    );
  }
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#attributes' => array(
      'class' => array(
        'element-invisible',
      ),
    ),
  );
  $form['actions']['cancel'] = array(
    '#markup' => l(t('Cancel'), 'admin/config/people/mo_auth/setup'),
    '#suffix' => '</div>',
    '#attributes' => array(
      'style' => 'display:inline-block',
    ),
  );
  return $form;
}