You are here

function _ldap_authentication_login_form_alter in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 8.4 ldap_authentication/ldap_authentication.module \_ldap_authentication_login_form_alter()
  2. 8.3 ldap_authentication/ldap_authentication.module \_ldap_authentication_login_form_alter()
  3. 7.2 ldap_authentication/ldap_authentication.inc \_ldap_authentication_login_form_alter()
  4. 7 ldap_authentication/ldap_authentication.inc \_ldap_authentication_login_form_alter()

helper function for ldap_authn_form_user_login_block_alter and ldap_authn_form_user_login_alter

@todo if form is being generated on non https and is set in preferences, set warning and end form development

2 calls to _ldap_authentication_login_form_alter()
ldap_authentication_form_user_login_alter in ldap_authentication/ldap_authentication.module
Implements hook_form_FORM_ID_alter(). for user_login
ldap_authentication_form_user_login_block_alter in ldap_authentication/ldap_authentication.module
Implements hook_form_FORM_ID_alter(). for user_login_block

File

ldap_authentication/ldap_authentication.inc, line 13
ldap_authentication helper functions

Code

function _ldap_authentication_login_form_alter(&$form, &$form_state, $form_id) {
  if (!($auth_conf = ldap_authentication_get_valid_conf())) {
    return;
  }
  elseif (!$auth_conf
    ->hasEnabledAuthenticationServers()) {
    return;
  }

  /**
   *
   * add validate function to test for ldap authentication
   * should be placed after user_login_authenticate_validate
   * 1. user_login_name_validate
   * 2. user_login_authenticate_validate
   * 3. external authentication validate functions
   * 4. user_login_final_validate
   *
   * as articulated above user_login_default_validators() in user.module
   *
   * without any other external authentication modules, this array will start out as:
   *    array('user_login_name_validate', 'user_login_authenticate_validate', 'user_login_final_validate')
   */
  if (@in_array('user_login_authenticate_validate', $form['#validate']) && $auth_conf->authenticationMode) {
    $key = array_search('user_login_authenticate_validate', $form['#validate']);
    $form['#validate'][$key] = 'ldap_authentication_core_override_user_login_authenticate_validate';
    array_splice($form['#validate'], $key + 1, 0, 'ldap_authentication_user_login_authenticate_validate');
  }
  if ($form_id == 'user_login_block') {
    $user_register = config('user.settings')
      ->get('register');
    $vars = array(
      'show_reset_pwd' => ldap_authentication_show_reset_pwd(),
      'auth_conf' => $auth_conf,
    );
    $form['links']['#markup'] = theme('ldap_authentication_user_login_block_links', $vars);
  }
  ldap_servers_disable_http_check($form);

  // Add help information for entering in username/password
  $auth_conf = ldap_authentication_get_valid_conf();
  if ($auth_conf) {
    if (isset($auth_conf->loginUIUsernameTxt)) {
      $form['name']['#description'] = t($auth_conf->loginUIUsernameTxt);
    }
    if (isset($auth_conf->loginUIPasswordTxt)) {
      $form['pass']['#description'] = t($auth_conf->loginUIPasswordTxt);
    }
  }
}