You are here

function ldapdata_user_login in LDAP integration 5.2

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

File

./ldapdata.module, line 540

Code

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

  // The whole point of implementing this hook is getting the
  // e-mail address written to the DB as soon as possible.
  // This is because it could not be written along with the rest
  // of the user info when the user was first created in
  // _ldapauth_ldap_login at the ldapauth module
  $mapping_type = _ldapdata_ldap_info($user, 'mapping_type');
  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 login: user {$user->name}'s data could not be read in the LDAP directory", WATCHDOG_WARNING);
    return;
  }
  $entry = $ldap
    ->retrieveAttributes($user->ldap_dn);
  $ldap
    ->disconnect();
  $d2l_mappings = _ldapdata_reverse_mappings($user->ldap_config);
  if (isset($d2l_mappings['mail'])) {
    $mail_attr = strtolower($d2l_mappings['mail']);
    $mail = $entry[$mail_attr][0];
    if ($mail != $user->mail) {
      user_save($user, array(
        'mail' => $mail,
      ));
    }
  }
}