small changes

This commit is contained in:
2026-09-11 10:34:44 +02:00
parent b8f9430827
commit fb152bd023
3 changed files with 15 additions and 26 deletions
+2 -1
View File
@@ -11,7 +11,8 @@ try {
$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
} catch(PDOException $e) { } catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage(); echo json_encode(["error" => "error.connect.faild"]);
exit;
} }
+11 -24
View File
@@ -12,7 +12,7 @@ $nimrodLDAP = new Connection([
]); ]);
if (!isset($_POST['uporabnik']) || !isset($_POST['geslo'])) { if (!isset($_POST['uporabnik']) || !isset($_POST['geslo'])) {
echo json_encode(["napaka" => "manjkajo podatki"]); echo json_encode(["error" => "error.user.login.missing"]);
exit; exit;
} }
@@ -22,17 +22,22 @@ $geslo = $_POST['geslo'];
try { try {
$nimrodLDAP->connect(); $nimrodLDAP->connect();
} catch (Exception $e) { } catch (Exception $e) {
echo 'napaka pri povezavi na LDap'; echo json_encode(["error" => "error.user.login.connect"]);
echo $e;
exit; exit;
} }
$LUser = $nimrodLDAP->query()->findBy('samaccountname', $username); $LUser = $nimrodLDAP->query()->findBy('samaccountname', $username);
if (empty($LUser)) { if (empty($LUser)) {
echo json_encode(["napaka" => "uporabnik ni najden"]); echo json_encode(["error" => "error.user.login.notFound"]);
exit; exit;
} }
$emailUserja = $LUser['userprincipalname'][0];
$user = $LUser['distinguishedname'][0];
if (!$nimrodLDAP->auth()->attempt($user, $geslo, $stayAuthenticated = true)) {
echo json_encode(["error" => "error.user.login.wrongPassword"]);
exit;
}
$vGrupah = $LUser['memberof']; $vGrupah = $LUser['memberof'];
$dGrupe = [ $dGrupe = [
@@ -44,14 +49,7 @@ $razlikaGrup = array_intersect(
array_map('strtolower', $dGrupe) array_map('strtolower', $dGrupe)
); );
if (count($razlikaGrup) <= 0) { if (count($razlikaGrup) <= 0) {
echo json_encode(["napaka" => "nimaš pravic skupinskih"]); echo json_encode(["error" => "error.user.login.groupRight"]);
exit;
}
$emailUserja = $LUser['userprincipalname'][0];
$user = $LUser['distinguishedname'][0];
if (!$nimrodLDAP->auth()->attempt($user, $geslo, $stayAuthenticated = true)) {
echo json_encode(["napaka" => "napacno geslo"]);
exit; exit;
} }
@@ -78,15 +76,4 @@ if ($obstojeciUporabnik) {
$_SESSION['displayname'] = $uporabnik; $_SESSION['displayname'] = $uporabnik;
$_SESSION['email'] = $email; $_SESSION['email'] = $email;
echo json_encode(["res" => "uspesno"]); echo json_encode(["res" => "res.user.login.true"]);
+2 -1
View File
@@ -1,2 +1,3 @@
<?php <?php
session_destroy(); session_destroy();
echo json_encode(["res" => "res.user.loginout.true"]);