You are here

function tfa_code_form in Two-factor Authentication (TFA) 7

Same name and namespace in other branches
  1. 6 tfa.pages.inc \tfa_code_form()

Form for code entry.

1 string reference to 'tfa_code_form'
tfa_menu in ./tfa.module
Implements hook_menu().

File

./tfa.pages.inc, line 10
tfa.pages.inc

Code

function tfa_code_form($form, $form_state, $uid, $hash = NULL) {

  // Check flood.
  if (!flood_is_allowed('tfa_validate', variable_get('tfa_hourly_threshold', 5))) {
    drupal_set_message(t('You have reached the threshold for incorrect code entry attempts. Please try again later.'), 'error');
    return drupal_access_denied();
  }
  $account = user_load($uid);
  $form['desc'] = array(
    '#markup' => t('Enter your received login code to continue.'),
  );
  $form['uid'] = array(
    '#type' => 'value',
    '#value' => $uid,
  );
  $form['code'] = array(
    '#type' => 'textfield',
    '#title' => t('Code'),
    '#required' => TRUE,
  );

  // Provide option to resend code.
  $form['resend'] = array(
    '#type' => 'fieldset',
    '#title' => t('Resend code'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('If you have not received the code you may resend it. You can only resend the code !count times per hour.', array(
      '!count' => variable_get('tfa_hourly_threshold', 5),
    )),
  );
  $form['resend']['send'] = array(
    '#type' => 'submit',
    '#value' => t('Resend code'),
    '#limit_validation_errors' => array(),
    '#submit' => array(
      'tfa_resend_code',
    ),
  );
  $form['login'] = array(
    '#type' => 'submit',
    '#value' => t('Log in'),
  );
  return $form;
}