some reorganization of code

This commit is contained in:
Uwe Steinmann 2023-08-16 17:40:14 +02:00
parent eae779832f
commit 7b8f3ef0bb

View File

@ -115,35 +115,54 @@ class SeedDMS_LdapAuthentication extends SeedDMS_Authentication {
$dn = $tmpDN; $dn = $tmpDN;
} }
/* Now do the actual authentication of the user */ /* Check if user already exists in the database. Return with an error
$bind = @ldap_bind($ds, $dn, $password); * only if the sql statements fails, but not if no user was found.
*/
$user = $dms->getUserByLogin($username); $user = $dms->getUserByLogin($username);
if($user === false) { if($user === false) {
ldap_close($ds); ldap_close($ds);
return false; return false;
} }
if ($bind) {
// Successfully authenticated. Now check to see if the user exists within
// the database. If not, add them in if _restricted is not set,
// but do not add their password.
if (is_null($user) && !$settings->_restricted) {
// Retrieve the user's LDAP information.
if (isset($settings->_ldapFilter) && strlen($settings->_ldapFilter) > 0) {
$search = ldap_search($ds, $settings->_ldapBaseDN, "(&(".$ldapSearchAttribut.$username.")".$settings->_ldapFilter.")");
} else {
$search = ldap_search($ds, $settings->_ldapBaseDN, $ldapSearchAttribut.$username);
}
if (!is_bool($search)) { /* Now do the actual authentication of the user */
$info = ldap_get_entries($ds, $search); $bind = @ldap_bind($ds, $dn, $password);
if (!$bind) {
ldap_close($ds);
return false;
}
<<<<<<< Updated upstream
if (!is_bool($info) && $info["count"]==1 && $info[0]["count"]>0) { if (!is_bool($info) && $info["count"]==1 && $info[0]["count"]>0) {
$user = $dms->addUser($username, null, $info[0]['cn'][0], $info[0]['mail'][0], $settings->_language, $settings->_theme, "", 0); $user = $dms->addUser($username, null, $info[0]['cn'][0], $info[0]['mail'][0], $settings->_language, $settings->_theme, "", 0);
=======
// Successfully authenticated. Now check to see if the user exists within
// the database. If not, add them in if _restricted is not set,
// but do not add their password.
if (!$settings->_restricted) {
// Retrieve the user's LDAP information.
if (isset($settings->_ldapFilter) && strlen($settings->_ldapFilter) > 0) {
$search = ldap_search($ds, $settings->_ldapBaseDN, "(&(".$ldapSearchAttribut.$username.")".$settings->_ldapFilter.")");
} else {
$search = ldap_search($ds, $settings->_ldapBaseDN, $ldapSearchAttribut.$username);
}
if (!is_bool($search)) {
$info = ldap_get_entries($ds, $search);
if (!is_bool($info) && $info["count"]==1 && $info[0]["count"]>0) {
if (is_null($user)) {
$user = $dms->addUser($username, null, $info[0]['cn'][0], $info[0]['mail'][0], $settings->_language, $settings->_theme, "", 3);
} else {
if(isset($info[0]['cn'][0]) && ($info[0]['cn'][0] != $user->getFullName())) {
$user->setFullName($info[0]['cn'][0]);
}
if(isset($info[0]['mail'][0]) && ($info[0]['mail'][0] != $user->getEmail())) {
$user->setEmail($info[0]['mail'][0]);
}
>>>>>>> Stashed changes
} }
} }
} }
} elseif($user) {
$user = false;
} }
ldap_close($ds); ldap_close($ds);