LDAP : start implementing user update function after LDAP connexion

This commit is contained in:
Maxime Kohlhaas 2013-01-30 16:50:28 +01:00
parent 81d5fa87e0
commit faccc978b4
2 changed files with 34 additions and 2 deletions

View File

@ -148,6 +148,8 @@ function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest)
// ldap2dolibarr synchronisation
if ($login && ! empty($conf->ldap->enabled) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr')
{
dol_syslog("functions_ldap::check_user_password_ldap Sync ldap2dolibarr");
// On charge les attributs du user ldap
if ($ldapdebug) print "DEBUG: login ldap = ".$login."<br>\n";
$resultFetchLdapUser = $ldap->fetch($login,$userSearchFilter);
@ -164,6 +166,7 @@ function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest)
$resultFetchUser=$user->fetch('',$login,$sid);
if ($resultFetchUser > 0)
{
dol_syslog("functions_ldap::check_user_password_ldap Sync user found id=".$user->id);
// On verifie si le login a change et on met a jour les attributs dolibarr
if ($user->login != $ldap->login && $ldap->login)
{
@ -171,7 +174,8 @@ function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest)
$user->update($user);
// TODO Que faire si update echoue car on update avec un login deja existant.
}
//$resultUpdate = $user->update_ldap2dolibarr();
$resultUpdate = $user->update_ldap2dolibarr($ldap);
}
}
}

View File

@ -1153,7 +1153,7 @@ class User extends CommonObject
{
// Si mot de passe saisi et different de celui en base
$result=$this->setPassword($user,$this->pass,0,$notrigger,$nosyncmemberpass);
if (! $nbrowsaffected) $nbrowsaffected++;
if (! $nbrowsaffected) $nbrowsaffected++;
}
}
@ -2072,6 +2072,34 @@ class User extends CommonObject
}
}
/**
* Update user using data from the LDAP
* // TODO: Voir pourquoi le update met à jour avec toutes les valeurs vide (global $user écrase ?)
*/
function update_ldap2dolibarr(&$ldapuser) {
global $user, $conf;
$this->firstname=$ldapuser->{$conf->global->LDAP_FIELD_FIRSTNAME};
$this->lastname=$ldapuser->{$conf->global->LDAP_FIELD_NAME};
$this->login=$ldapuser->{$conf->global->LDAP_FIELD_LOGIN};
$this->pass=$ldapuser->{$conf->global->LDAP_FIELD_PASSWORD};
$this->pass_indatabase_crypted=$ldapuser->{$conf->global->LDAP_FIELD_PASSWORD_CRYPTED};
$this->office_phone=$ldapuser->{$conf->global->LDAP_FIELD_PHONE};
$this->user_mobile=$ldapuser->{$conf->global->LDAP_FIELD_MOBILE};
$this->office_fax=$ldapuser->{$conf->global->LDAP_FIELD_FAX};
$this->email=$ldapuser->{$conf->global->LDAP_FIELD_MAIL};
$this->ldap_sid=$ldapuser->{$conf->global->LDAP_FIELD_SID};
$this->job=$ldapuser->{$conf->global->LDAP_FIELD_TITLE};
$this->note=$ldapuser->{$conf->global->LDAP_FIELD_DESCRIPTION};
$result = $this->update($user);
dol_syslog(get_class($this)."::update_ldap2dolibarr result=".$result, LOG_DEBUG);
return $result;
}
}
?>