1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dotclear2_ynh.git synced 2024-09-03 18:26:29 +02:00

add a try catch block, improve the ldap auth class

This commit is contained in:
Kay0u 2021-12-16 22:01:27 +01:00
parent 810121c232
commit f6cb024d24
No known key found for this signature in database
GPG key ID: AE1DCADB6415A156

View file

@ -20,7 +20,6 @@ class ldapDcAuth extends dcAuth
if ($ds) if ($ds)
{ {
ldap_set_option ($ds, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option ($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
if (ldap_bind($ds, "uid=".$user_id.",ou=users,".$this->base, $pwd)) if (ldap_bind($ds, "uid=".$user_id.",ou=users,".$this->base, $pwd))
{ {
# search the user in ldap, and get infos # search the user in ldap, and get infos
@ -29,6 +28,8 @@ class ldapDcAuth extends dcAuth
$info = ldap_get_entries($ds, $sr); $info = ldap_get_entries($ds, $sr);
if ($info["count"] == 1) if ($info["count"] == 1)
{
try
{ {
$this->con->begin(); $this->con->begin();
$cur = $this->con->openCursor($this->user_table); $cur = $this->con->openCursor($this->user_table);
@ -71,16 +72,24 @@ class ldapDcAuth extends dcAuth
$this->sudo(array($this->core, 'setUserBlogPermissions'), $user_id, 'default', array('usage'=>true)); # Can change this, PR are welcome $this->sudo(array($this->core, 'setUserBlogPermissions'), $user_id, 'default', array('usage'=>true)); # Can change this, PR are welcome
} }
$this->con->commit(); $this->con->commit();
}
catch (Exception $e)
{
# In case of error we cancel and return "false"
$this->con->rollback();
return false;
}
# The previous operations proceeded without error, # The previous operations proceeded without error,
# we can now call the parent method # we can now call the parent method
return parent::checkUser($user_id, $pwd); return parent::checkUser($user_id, $pwd);
} }
} }
else
{
error_log("Failed to connect with the user ".$user_id);
} }
# In case of error we cancel and return "false" }
$this->con->rollback(); return parent::checkUser($user_id, $pwd);
return false;
} }
} }
?> ?>