You are here

function ldapdata_user_load in LDAP integration 5.2

Same name and namespace in other branches
  1. 5 ldapdata.module \ldapdata_user_load()
1 call to ldapdata_user_load()
ldapdata_user in ./ldapdata.module
Implements hook_user()

File

./ldapdata.module, line 465

Code

function ldapdata_user_load(&$user) {
  global $ldap;

  // setup the global $ldap object
  if (!_ldapdata_ldap_init($user)) {
    return;
  }
  $mapping_type = _ldapdata_ldap_info($user, 'mapping_type');

  // See http://drupal.org/node/91786 about user_node()
  // User can be edited by the user or by other authorized users.
  if (!$user->ldap_authentified || $mapping_type == LDAP_MAP_NOTHING) {
    return;
  }
  $bind_info = _ldapdata_edition($user);
  if (!$ldap
    ->connect($bind_info[0], $bind_info[1])) {
    watchdog('user', "User load: user {$user->name}'s data could not be read in the LDAP directory", WATCHDOG_WARNING);
    return;
  }
  $entry = $ldap
    ->retrieveAttributes($user->ldap_dn);
  if ($entry) {
    $ldap_drupal_mappings = array_flip(_ldapdata_reverse_mappings($user->ldap_config));
    foreach ($ldap_drupal_mappings as $ldap_attr => $drupal_field) {
      if (isset($user->{$drupal_field}) && $ldap_attr && $drupal_field != 'access') {
        if ($drupal_field != 'pass') {
          $user->{$drupal_field} = $entry[strtolower($ldap_attr)][0];
        }
      }
    }
    ldapdata_user_profile_load($user);
  }
  $ldap
    ->disconnect();
}