From 937c06ef8d706a76fcc42bbcbdbde5e177341547 Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Sat, 12 Sep 2026 00:08:24 +0200 Subject: [PATCH] Login Done --- php/auto/auto.php | 12 +++++++++++- php/user/is_loged_in.php | 10 +++++++--- php/user/ldapLogin.php | 23 ++++++++++++++--------- php/user/logout.php | 1 + typed-router.d.ts | 15 +++++++++++++++ vue/components/Sidebar.vue | 1 + vue/locales/en.json | 15 ++++++++------- vue/locales/sl.json | 3 ++- vue/routes/login.vue | 32 +++++++++++++++++++++++++------- vue/routes/logout.vue | 18 ++++++++++++++++++ 10 files changed, 102 insertions(+), 28 deletions(-) create mode 100644 vue/routes/logout.vue diff --git a/php/auto/auto.php b/php/auto/auto.php index 9de72e6..c81ca23 100644 --- a/php/auto/auto.php +++ b/php/auto/auto.php @@ -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'; \ No newline at end of file +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]; + } + } +} diff --git a/php/user/is_loged_in.php b/php/user/is_loged_in.php index 10029a1..0c1ed56 100644 --- a/php/user/is_loged_in.php +++ b/php/user/is_loged_in.php @@ -1,9 +1,13 @@ "res.user.login.true", + "displayname" => $_SESSION['displayname'] +]); \ No newline at end of file diff --git a/php/user/ldapLogin.php b/php/user/ldapLogin.php index 7193e3e..5f46e8a 100644 --- a/php/user/ldapLogin.php +++ b/php/user/ldapLogin.php @@ -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; } diff --git a/php/user/logout.php b/php/user/logout.php index d6ab385..9a21b9b 100644 --- a/php/user/logout.php +++ b/php/user/logout.php @@ -1,3 +1,4 @@ "res.user.loginout.true"]); \ No newline at end of file diff --git a/typed-router.d.ts b/typed-router.d.ts index 9c9c0c4..9b6b7c9 100644 --- a/typed-router.d.ts +++ b/typed-router.d.ts @@ -45,6 +45,13 @@ declare module 'vue-router/auto-routes' { Record, | never >, + '/logout': RouteRecordInfo< + '/logout', + '/logout', + Record, + Record, + | never + >, '/settings': RouteRecordInfo< '/settings', '/settings', @@ -103,6 +110,14 @@ declare module 'vue-router/auto-routes' { pathParamNames: | never } + 'vue/routes/logout.vue': { + routes: + | '/logout' + views: + | never + pathParamNames: + | never + } 'vue/routes/settings.vue': { routes: | '/settings' diff --git a/vue/components/Sidebar.vue b/vue/components/Sidebar.vue index b4457ea..4054daa 100644 --- a/vue/components/Sidebar.vue +++ b/vue/components/Sidebar.vue @@ -51,5 +51,6 @@ const items = [ // { label: 'Reports', icon: 'fa-chart-line', to: '/reports' }, { label: 'menu.userSettings', icon: 'fa-user-gear', to: '/user_settings' }, { label: 'menu.settings', icon: 'fa-gear', to: '/settings' }, + { label: 'menu.logout', icon: 'fa-right-from-bracket', to: '/logout' }, ]; diff --git a/vue/locales/en.json b/vue/locales/en.json index 064f71a..f4cb7b2 100644 --- a/vue/locales/en.json +++ b/vue/locales/en.json @@ -1,17 +1,18 @@ { - "userSettings":{ + "userSettings": { "themeSelect": "Select theme", - "light":"Light", - "dark":"Dark" + "light": "Light", + "dark": "Dark" }, "menu": { "settings": "Settings", "userSettings": "User settings", - "dashboard": "Dashboard" + "dashboard": "Dashboard", + "logout": "Logout" }, - "settings":{ - "users":"Users", - "groups":"Groups" + "settings": { + "users": "Users", + "groups": "Groups" }, "common": { "save": "Save", diff --git a/vue/locales/sl.json b/vue/locales/sl.json index c9ce650..8ad7eee 100644 --- a/vue/locales/sl.json +++ b/vue/locales/sl.json @@ -7,7 +7,8 @@ "menu": { "settings": "Nastavitve", "userSettings": "Uporabniške nastavitve", - "dashboard": "Nadzorna plošča" + "dashboard": "Nadzorna plošča", + "logout": "Odjava" }, "settings": { "users": "Uporabni", diff --git a/vue/routes/login.vue b/vue/routes/login.vue index 1de61bb..153420f 100644 --- a/vue/routes/login.vue +++ b/vue/routes/login.vue @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/vue/routes/logout.vue b/vue/routes/logout.vue new file mode 100644 index 0000000..5b17913 --- /dev/null +++ b/vue/routes/logout.vue @@ -0,0 +1,18 @@ + + \ No newline at end of file