You are here

public function TfaTotpSetup::getSetupForm in TFA Basic plugins 7

@copydoc TfaSetupPluginInterface::getSetupForm()

Overrides TfaSetupPluginInterface::getSetupForm

File

includes/tfa_totp.inc, line 198
classes for tfa_totp

Class

TfaTotpSetup
Class TfaTotpSetup

Code

public function getSetupForm(array $form, array &$form_state) {
  $items = array(
    l('Google Authenticator (Android/iPhone/BlackBerry)', 'https://support.google.com/accounts/answer/1066447?hl=en', array(
      'attributes' => array(
        'target' => '_blank',
      ),
    )),
    l('Authy (Android/iPhone)', 'https://www.authy.com/app/', array(
      'attributes' => array(
        'target' => '_blank',
      ),
    )),
    l('Authenticator (Windows Phone)', 'http://www.windowsphone.com/en-us/store/app/authenticator/021dd79f-0598-e011-986b-78e7d1fa76f8', array(
      'attributes' => array(
        'target' => '_blank',
      ),
    )),
    l('FreeOTP (Android)', 'https://play.google.com/store/apps/details?id=org.fedorahosted.freeotp', array(
      'attributes' => array(
        'target' => '_blank',
      ),
    )),
    l('GAuth Authenticator (Firefox OS, desktop, others)', 'https://github.com/gbraad/gauth', array(
      'attributes' => array(
        'target' => '_blank',
      ),
    )),
  );
  $form['apps'] = array(
    '#type' => 'markup',
    '#markup' => theme('item_list', array(
      'items' => $items,
      'title' => t('Install authentication code application on your mobile or desktop device:'),
    )),
  );
  $form['info'] = array(
    '#type' => 'markup',
    '#markup' => t('<p>The two-factor authentication application will be used during this setup and for generating codes during regular authentication. If the application supports it, scan the QR code below to get the setup code otherwise you can manually enter the text code.</p>'),
  );
  $form['seed'] = array(
    '#type' => 'textfield',
    '#value' => $this->seed,
    '#disabled' => TRUE,
    '#allow_focus' => TRUE,
    '#description' => t('Enter this code into your two-factor authentication app or scan the QR code below.'),
  );

  // QR image of seed.
  if (file_exists(drupal_get_path('module', 'tfa_basic') . '/includes/qrcodejs/qrcode.min.js')) {
    $form['qr_image_wrapper']['qr_image'] = array(
      '#markup' => '<div id="tfa-qrcode"></div>',
    );
    $qrdata = 'otpauth://totp/' . $this
      ->accountName() . '?secret=' . $this->seed;
    $form['qr_image_wrapper']['qr_image']['#attached']['library'][] = array(
      'tfa_basic',
      'qrcodejs',
    );
    $form['qr_image_wrapper']['qr_image']['#attached']['js'][] = array(
      'data' => 'jQuery(document).ready(function () { new QRCode(document.getElementById("tfa-qrcode"), "' . $qrdata . '");});',
      'type' => 'inline',
      'scope' => 'footer',
      'weight' => 5,
    );
  }
  else {
    $form['qr_image'] = array(
      '#markup' => '<img src="' . $this
        ->getQrCodeUrl($this->seed) . '" alt="QR code for TFA setup">',
    );
  }

  // Include code entry form.
  $form = $this
    ->getForm($form, $form_state);
  $form['actions']['login']['#value'] = t('Verify and save');

  // Alter code description.
  $form['code']['#description'] = t('A verification code will be generated after you scan the above QR code or manually enter the setup code. The verification code is six digits long.');
  return $form;
}