You are here

function ldapgroups_user_test_validate in LDAP integration 6

Validate the supplied test info.

_state

Parameters

Array $form:

File

./ldapgroups.admin.inc, line 416
Module admin page callbacks.

Code

function ldapgroups_user_test_validate($form, &$form_state) {
  module_load_include('inc', 'ldapgroups', 'ldapgroups');
  $values = $form_state['values'];
  if ($values['server'] && $values['dn'] && $values['test_user']) {
    form_set_error('', t('Can not have all three fields filled.  Use only a Drupal name or LDAP server/dn pair.'));
    return;
  }
  if ($values['server'] && $values['dn']) {
    if (!ldapgroups_is_configured($values['server'])) {
      form_set_error('', t('Server, @server, has no LDAP group settings defined yet.', array(
        "@server" => $values['server'],
      )));
    }
    return;
  }
  $account = user_load(array(
    'name' => $values['test_user'],
  ));
  if (!$account) {
    form_set_error('test_user', t("Invalid user name"));
    return;
  }
  if (!$account->ldap_authentified || $account->ldap_authentified != 1) {
    form_set_error('test_user', t("User was not an LDAP authenticated user."));
    return;
  }
  if (!ldapgroups_is_configured($account->ldap_config)) {
    form_set_error('', t('Server, @server, has no LDAP group settings defined yet.', array(
      "@server" => $account->ldap_config,
    )));
    return;
  }
  $form_state['values']['account'] = $account;
}