Login Done

This commit is contained in:
2026-09-12 00:08:24 +02:00
parent fb09048e45
commit 937c06ef8d
10 changed files with 102 additions and 28 deletions
+11 -1
View File
@@ -7,4 +7,14 @@ $dotenv = Dotenv\Dotenv::createImmutable($_SERVER['DOCUMENT_ROOT']); // dir cont
$dotenv->load();
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/connection.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/user.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/user.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
if (str_contains($contentType, 'application/json') || str_contains($contentType, 'text/plain')) {
$input = json_decode(file_get_contents("php://input"), true);
if (is_array($input)) {
$_POST = [...$_POST, ...$input];
}
}
}
+7 -3
View File
@@ -1,9 +1,13 @@
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/auto.php';
if (!isset($_SESSION['id'])) {
http_response_code(401);
exit;
http_response_code(401);
exit;
}
http_response_code(200);
echo 'ok';
echo json_encode([
"res" => "res.user.login.true",
"displayname" => $_SESSION['displayname']
]);
+14 -9
View File
@@ -2,8 +2,8 @@
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/auto.php';
if ($_ENV['DEV_EMAIL']) {
$email = $_ENV['DEV_EMAIL'];
if (isset($_ENV['DEV_LOGIN'])) {
$email = $_POST['username'];
$find = $conn->prepare("SELECT user_id, username, display_name FROM users WHERE email = :email");
$find->execute([':email' => $email]);
$obstojeciUporabnik = $find->fetch();
@@ -22,30 +22,33 @@ if ($_ENV['DEV_EMAIL']) {
use LdapRecord\Connection;
$nimrodLDAP = new Connection([
'hosts' => [getenv('LDAP_HOST')],
'hosts' => [$_ENV['LDAP_HOST']],
'port' => 389,
'base_dn' => getenv('LDAP_BASEDN'),
'username' => getenv('LDAP_USER'),
'password' => getenv('LDAP_SECRET')
'base_dn' => $_ENV['LDAP_BASEDN'],
'username' => $_ENV['LDAP_USER'],
'password' => $_ENV['LDAP_SECRET']
]);
if (!isset($_POST['uporabnik']) || !isset($_POST['geslo'])) {
if (!isset($_POST['username']) || !isset($_POST['pass'])) {
http_response_code(401);
echo json_encode(["error" => "error.user.login.missing"]);
exit;
}
$username = $_POST['uporabnik'];
$geslo = $_POST['geslo'];
$username = $_POST['username'];
$geslo = $_POST['pass'];
try {
$nimrodLDAP->connect();
} catch (Exception $e) {
http_response_code(401);
echo json_encode(["error" => "error.user.login.connect"]);
exit;
}
$LUser = $nimrodLDAP->query()->findBy('samaccountname', $username);
if (empty($LUser)) {
http_response_code(401);
echo json_encode(["error" => "error.user.login.notFound"]);
exit;
}
@@ -53,6 +56,7 @@ if (empty($LUser)) {
$emailUserja = $LUser['userprincipalname'][0];
$user = $LUser['distinguishedname'][0];
if (!$nimrodLDAP->auth()->attempt($user, $geslo, $stayAuthenticated = true)) {
http_response_code(401);
echo json_encode(["error" => "error.user.login.wrongPassword"]);
exit;
}
@@ -67,6 +71,7 @@ $razlikaGrup = array_intersect(
array_map('strtolower', $dGrupe)
);
if (count($razlikaGrup) <= 0) {
http_response_code(401);
echo json_encode(["error" => "error.user.login.groupRight"]);
exit;
}
+1
View File
@@ -1,3 +1,4 @@
<?php
session_start();
session_destroy();
echo json_encode(["res" => "res.user.loginout.true"]);