You are here

function ga_login_form_alter in Google Authenticator login 6

File

./ga_login.module, line 133

Code

function ga_login_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_login_block' || $form_id == 'user_login') {

    // Re-arrange and add validation handlers.
    array_unshift($form['#validate'], $form['#validate'][0]);
    $form['#validate'][1] = 'ga_login_user_login_validate';
    $form['#validate'][] = 'ga_login_user_login_validate_code_needed';
    $form['gacode'] = array(
      '#type' => 'textfield',
      '#title' => 'Code',
      '#maxlength' => 6,
      '#size' => 6,
      '#required' => FALSE,
    );
    $form['name']['#weight'] = 1;
    $form['pass']['#weight'] = 2;
    $form['gacode']['#weight'] = 3;
    $form['submit']['#weight'] = 4;
    if (isset($form['links'])) {
      $form['links']['#weight'] = 5;
    }
  }
  elseif ($form_id == 'user_profile_form') {
    $account = user_load($form['#uid']);
    $register = $account->uid > 0 ? FALSE : TRUE;

    // Add some more settings to the user profile form.
    $form['ga_login'] = array(
      '#type' => 'fieldset',
      '#title' => t('Two factor authentication'),
      '#weight' => 1,
      '#access' => !$register && user_access('login without code', $account),
    );
    $data = unserialize($account->data);
    $form['ga_login']['ga_login_force_tfa'] = array(
      '#type' => 'checkbox',
      '#title' => t('Protect my account with two-factor-authentication'),
      '#default_value' => isset($data['ga_login_force_tfa']) ? $data['ga_login_force_tfa'] : FALSE,
      '#description' => t('Check this box to force two-factor-authentication during login. If you decide to do so and haven\'t yet created your key, then please also refer to <a href="@url">GA Login</a>.', array(
        '@url' => url('ga_login/create'),
      )),
    );
  }
}