diff --git a/src/ifm.js b/src/ifm.js index f83f88b..73f37e7 100644 --- a/src/ifm.js +++ b/src/ifm.js @@ -1921,14 +1921,20 @@ function IFM(params) { }, dataType: "json", success: function(e) { - self.hideModal(); - self.initApplication(); + if (e.status != "ERROR") { + self.hideModal(); + self.initApplication(); + } else { + var errorlogin = document.getElementsByClassName('alert')[0]; + errorlogin.classList.remove("d-none"); + errorlogin.innerHTML = e.message; + } + }, error: function(e) { var errorlogin = document.getElementsByClassName('alert')[0]; errorlogin.classList.remove("d-none"); - errorlogin.innerHTML = "Authentication failed" - //self.showMessage("Authentication failed", "e"); + errorlogin.innerHTML = "Authentication failed"; } }); } @@ -1937,10 +1943,6 @@ function IFM(params) { self.initApplication(); } } - // }, - // error: function(resp) { - // throw new Error("Not authenticated"); - // } }); }; diff --git a/src/main.php b/src/main.php index 3298992..142bd30 100644 --- a/src/main.php +++ b/src/main.php @@ -1028,7 +1028,8 @@ f00bar; } $u = $uuid . "=" . $user . "," . $basedn; if (!$ds = ldap_connect($ldap_server)) { - trigger_error("Could not reach the ldap server.", E_USER_ERROR); + throw new IFMException("Could not reach the ldap server." , true); + //trigger_error("Could not reach the ldap server.", E_USER_ERROR); return false; } ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); @@ -1036,16 +1037,18 @@ f00bar; $ldbind = @ldap_bind($ds, $u, $pass); if ($ldbind) { if ($ufilter) { - if (ldap_count_entries($ds, ldap_search($ds, $u, $ufilter)) > 0) { + if (ldap_count_entries($ds, ldap_search($ds, $u, $ufilter)) == 1) { $authenticated = true; } else { - trigger_error("User not allowed.", E_USER_ERROR); + throw new IFMException("User not allowed." , true); + //trigger_error("User not allowed.", E_USER_ERROR); $authenticated = false; } } else $authenticated = true; } else { - trigger_error(ldap_error($ds), E_USER_ERROR); + throw new IFMException(ldap_error($ds) , true); + //trigger_error(ldap_error($ds), E_USER_ERROR); $authenticated = false; } ldap_unbind($ds);