You are here

function _ga_login_code_approve_form in Google Authenticator login 7

Form to create a new code - step 2.

1 call to _ga_login_code_approve_form()
ga_login_create_form in ./ga_login.pages.inc
Form to create a new code.

File

./ga_login.pages.inc, line 162
ga_login pages.

Code

function _ga_login_code_approve_form($form, &$form_state, $account) {
  $url = $form_state['url'];
  $data = $form_state['data'];
  $form['warning'] = array(
    '#type' => 'item',
    '#markup' => t("This login code will only be activated on this site once you've submitted this form. As long as you don't submit this form, you will not be able to log in on this site using this code."),
    '#title' => t('Warning!'),
  );
  $form['type'] = array(
    '#type' => 'item',
    '#markup' => $data['tokentype'] == 'TOTP' ? t('Time-based') : t('Counter-based'),
    '#title' => t('Type'),
  );
  $form['url'] = array(
    '#type' => 'item',
    '#markup' => $url,
    '#title' => t('URL'),
  );
  $form['account'] = array(
    '#type' => 'item',
    '#markup' => $data['username'],
    '#title' => t('Account'),
  );
  $form['key'] = array(
    '#type' => 'item',
    '#markup' => '<span class="secret-key">' . $data['secret'] . '</span>',
    '#title' => t('Key'),
  );

  // Generate barcode.
  $img = $file = '';
  if (module_exists('mobile_codes')) {
    $variables = array(
      'data' => $url,
      'attributes' => array(
        '#preset' => 'ga_login',
      ),
    );
    $path = mobile_codes_process_url($variables['data'], $variables['attributes']);
    $file = 'public://mobile_codes/' . md5(serialize($path)) . '.png';
    $img = theme('mobilecode', $variables);
  }
  if (!empty($img)) {
    $form['current'] = array(
      '#type' => 'item',
      '#title' => t('Barcode'),
      '#markup' => $img,
    );
  }
  $form['code_image_path'] = array(
    '#type' => 'value',
    '#value' => $file,
  );
  $form['uid'] = array(
    '#type' => 'value',
    '#value' => $account->uid,
  );
  $form['verify_code'] = array(
    '#type' => 'gacode',
    '#uid' => $account->uid,
    '#title' => t('Code'),
    '#description' => t('Please enter the code that appears on your authenticator device.'),
    '#required' => TRUE,
    // Set a flag for the #element_validate callback not to check the db, as
    // this is a new code.
    '#_new_ga_code' => TRUE,
  );
  $form['approve_current_submit'] = array(
    '#type' => 'submit',
    '#value' => t('Use this code'),
  );
  return $form;
}