You are here

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

File

./mo_auth.module, line 397
Module file for miniOrange 2FA Module.

Code

function mo_auth_form_alter(&$form, $form_state, $form_id) {
  global $user;
  $uid = isset($_GET['uid']) ? $_GET['uid'] : '';
  if ($form_id == 'user_login_block' || $form_id == 'user_login_form' || $form_id == 'user_login') {
    $my = isset($_GET['need_second_factor_pass']) ? $_GET['need_second_factor_pass'] : 0;
    $val1 = variable_get('mo_auth_two_factor_instead_password');
    $val2 = variable_get('mo_auth_enable_two_factor');
    if ($val1 == '1' && $val2 == '1' && $my != '1') {
      $output = array_diff_key($form, array_flip((array) [
        'pass',
      ]));
      $output1 = array_diff_key($output, array_flip((array) [
        'actions',
      ]));
      $output2 = array_diff_key($output1, array_flip((array) [
        '#validate',
      ]));
      $form = $output2;
      $form['minorange_login_tfa'] = array(
        '#type' => 'submit',
        '#value' => t('Login with 2nd Factor'),
        '#submit' => array(
          'mo_auth_form_alter_submit',
        ),
      );
    }
    else {
      $u = user_load($uid);
      $form['name']['#default_value'] = isset($u->name) ? $u->name : '';
    }
  }
  if ($form_id == 'user_profile_form' && user_is_logged_in()) {
    unset($form['mo_auth_password_checked']);
    if (in_array('administrator', $user->roles)) {
      $form['configured_auth_methods']['#disabled'] = TRUE;
    }
    else {
      unset($form['miniorange_registered_email'], $form['configured_auth_methods']);
    }
  }
}