Login Done
This commit is contained in:
@@ -8,3 +8,13 @@ $dotenv->load();
|
|||||||
|
|
||||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/connection.php';
|
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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/auto.php';
|
||||||
|
|
||||||
if (!isset($_SESSION['id'])) {
|
if (!isset($_SESSION['id'])) {
|
||||||
http_response_code(401);
|
http_response_code(401);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
http_response_code(200);
|
http_response_code(200);
|
||||||
echo 'ok';
|
echo json_encode([
|
||||||
|
"res" => "res.user.login.true",
|
||||||
|
"displayname" => $_SESSION['displayname']
|
||||||
|
]);
|
||||||
+14
-9
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/auto.php';
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/auto.php';
|
||||||
|
|
||||||
if ($_ENV['DEV_EMAIL']) {
|
if (isset($_ENV['DEV_LOGIN'])) {
|
||||||
$email = $_ENV['DEV_EMAIL'];
|
$email = $_POST['username'];
|
||||||
$find = $conn->prepare("SELECT user_id, username, display_name FROM users WHERE email = :email");
|
$find = $conn->prepare("SELECT user_id, username, display_name FROM users WHERE email = :email");
|
||||||
$find->execute([':email' => $email]);
|
$find->execute([':email' => $email]);
|
||||||
$obstojeciUporabnik = $find->fetch();
|
$obstojeciUporabnik = $find->fetch();
|
||||||
@@ -22,30 +22,33 @@ if ($_ENV['DEV_EMAIL']) {
|
|||||||
|
|
||||||
use LdapRecord\Connection;
|
use LdapRecord\Connection;
|
||||||
$nimrodLDAP = new Connection([
|
$nimrodLDAP = new Connection([
|
||||||
'hosts' => [getenv('LDAP_HOST')],
|
'hosts' => [$_ENV['LDAP_HOST']],
|
||||||
'port' => 389,
|
'port' => 389,
|
||||||
'base_dn' => getenv('LDAP_BASEDN'),
|
'base_dn' => $_ENV['LDAP_BASEDN'],
|
||||||
'username' => getenv('LDAP_USER'),
|
'username' => $_ENV['LDAP_USER'],
|
||||||
'password' => getenv('LDAP_SECRET')
|
'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"]);
|
echo json_encode(["error" => "error.user.login.missing"]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$username = $_POST['uporabnik'];
|
$username = $_POST['username'];
|
||||||
$geslo = $_POST['geslo'];
|
$geslo = $_POST['pass'];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$nimrodLDAP->connect();
|
$nimrodLDAP->connect();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
http_response_code(401);
|
||||||
echo json_encode(["error" => "error.user.login.connect"]);
|
echo json_encode(["error" => "error.user.login.connect"]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$LUser = $nimrodLDAP->query()->findBy('samaccountname', $username);
|
$LUser = $nimrodLDAP->query()->findBy('samaccountname', $username);
|
||||||
if (empty($LUser)) {
|
if (empty($LUser)) {
|
||||||
|
http_response_code(401);
|
||||||
echo json_encode(["error" => "error.user.login.notFound"]);
|
echo json_encode(["error" => "error.user.login.notFound"]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@@ -53,6 +56,7 @@ if (empty($LUser)) {
|
|||||||
$emailUserja = $LUser['userprincipalname'][0];
|
$emailUserja = $LUser['userprincipalname'][0];
|
||||||
$user = $LUser['distinguishedname'][0];
|
$user = $LUser['distinguishedname'][0];
|
||||||
if (!$nimrodLDAP->auth()->attempt($user, $geslo, $stayAuthenticated = true)) {
|
if (!$nimrodLDAP->auth()->attempt($user, $geslo, $stayAuthenticated = true)) {
|
||||||
|
http_response_code(401);
|
||||||
echo json_encode(["error" => "error.user.login.wrongPassword"]);
|
echo json_encode(["error" => "error.user.login.wrongPassword"]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@@ -67,6 +71,7 @@ $razlikaGrup = array_intersect(
|
|||||||
array_map('strtolower', $dGrupe)
|
array_map('strtolower', $dGrupe)
|
||||||
);
|
);
|
||||||
if (count($razlikaGrup) <= 0) {
|
if (count($razlikaGrup) <= 0) {
|
||||||
|
http_response_code(401);
|
||||||
echo json_encode(["error" => "error.user.login.groupRight"]);
|
echo json_encode(["error" => "error.user.login.groupRight"]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
session_start();
|
||||||
session_destroy();
|
session_destroy();
|
||||||
echo json_encode(["res" => "res.user.loginout.true"]);
|
echo json_encode(["res" => "res.user.loginout.true"]);
|
||||||
Vendored
+15
@@ -45,6 +45,13 @@ declare module 'vue-router/auto-routes' {
|
|||||||
Record<never, never>,
|
Record<never, never>,
|
||||||
| never
|
| never
|
||||||
>,
|
>,
|
||||||
|
'/logout': RouteRecordInfo<
|
||||||
|
'/logout',
|
||||||
|
'/logout',
|
||||||
|
Record<never, never>,
|
||||||
|
Record<never, never>,
|
||||||
|
| never
|
||||||
|
>,
|
||||||
'/settings': RouteRecordInfo<
|
'/settings': RouteRecordInfo<
|
||||||
'/settings',
|
'/settings',
|
||||||
'/settings',
|
'/settings',
|
||||||
@@ -103,6 +110,14 @@ declare module 'vue-router/auto-routes' {
|
|||||||
pathParamNames:
|
pathParamNames:
|
||||||
| never
|
| never
|
||||||
}
|
}
|
||||||
|
'vue/routes/logout.vue': {
|
||||||
|
routes:
|
||||||
|
| '/logout'
|
||||||
|
views:
|
||||||
|
| never
|
||||||
|
pathParamNames:
|
||||||
|
| never
|
||||||
|
}
|
||||||
'vue/routes/settings.vue': {
|
'vue/routes/settings.vue': {
|
||||||
routes:
|
routes:
|
||||||
| '/settings'
|
| '/settings'
|
||||||
|
|||||||
@@ -51,5 +51,6 @@ const items = [
|
|||||||
// { label: 'Reports', icon: 'fa-chart-line', to: '/reports' },
|
// { label: 'Reports', icon: 'fa-chart-line', to: '/reports' },
|
||||||
{ label: 'menu.userSettings', icon: 'fa-user-gear', to: '/user_settings' },
|
{ label: 'menu.userSettings', icon: 'fa-user-gear', to: '/user_settings' },
|
||||||
{ label: 'menu.settings', icon: 'fa-gear', to: '/settings' },
|
{ label: 'menu.settings', icon: 'fa-gear', to: '/settings' },
|
||||||
|
{ label: 'menu.logout', icon: 'fa-right-from-bracket', to: '/logout' },
|
||||||
];
|
];
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
+8
-7
@@ -1,17 +1,18 @@
|
|||||||
{
|
{
|
||||||
"userSettings":{
|
"userSettings": {
|
||||||
"themeSelect": "Select theme",
|
"themeSelect": "Select theme",
|
||||||
"light":"Light",
|
"light": "Light",
|
||||||
"dark":"Dark"
|
"dark": "Dark"
|
||||||
},
|
},
|
||||||
"menu": {
|
"menu": {
|
||||||
"settings": "Settings",
|
"settings": "Settings",
|
||||||
"userSettings": "User settings",
|
"userSettings": "User settings",
|
||||||
"dashboard": "Dashboard"
|
"dashboard": "Dashboard",
|
||||||
|
"logout": "Logout"
|
||||||
},
|
},
|
||||||
"settings":{
|
"settings": {
|
||||||
"users":"Users",
|
"users": "Users",
|
||||||
"groups":"Groups"
|
"groups": "Groups"
|
||||||
},
|
},
|
||||||
"common": {
|
"common": {
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
|
|||||||
+2
-1
@@ -7,7 +7,8 @@
|
|||||||
"menu": {
|
"menu": {
|
||||||
"settings": "Nastavitve",
|
"settings": "Nastavitve",
|
||||||
"userSettings": "Uporabniške nastavitve",
|
"userSettings": "Uporabniške nastavitve",
|
||||||
"dashboard": "Nadzorna plošča"
|
"dashboard": "Nadzorna plošča",
|
||||||
|
"logout": "Odjava"
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"users": "Uporabni",
|
"users": "Uporabni",
|
||||||
|
|||||||
+25
-7
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="columns is-vcentered" style="height: 50rem;">
|
<div class="columns is-vcentered" style="height: 50rem;">
|
||||||
<div class="column is-2 is-offset-5">
|
<div class="column is-4 is-offset-4">
|
||||||
<form @submit.prevent="logIn">
|
<form @submit.prevent="logIn">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ t('login.username') }}</label>
|
<label class="label">{{ t('login.username') }}</label>
|
||||||
@@ -25,29 +25,47 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { displayName, isLogedIn } from '../global';
|
import { displayName, isLogedIn } from '../global';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const route = useRouter();
|
const route = useRouter();
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
console.log("HE");
|
||||||
|
const res = await fetch("/php/user/is_loged_in.php");
|
||||||
|
if (res.ok) {
|
||||||
|
const body = await res.json();
|
||||||
|
displayName.value = body.displayname;
|
||||||
|
isLogedIn.value = true;
|
||||||
|
route.push("/");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
const userName = ref();
|
const userName = ref();
|
||||||
const password = ref();
|
const password = ref();
|
||||||
|
|
||||||
async function logIn(){
|
async function logIn() {
|
||||||
const mes = {
|
const mes = {
|
||||||
"username": userName.value,
|
"username": userName.value,
|
||||||
"pass": password.value
|
"pass": password.value
|
||||||
}
|
}
|
||||||
const res = await fetch("/php/user/ldapLogin.php", {
|
const res = await fetch("/php/user/ldapLogin.php", {
|
||||||
"body": mes,
|
"body": JSON.stringify(mes),
|
||||||
"method": "POST"
|
"method": "POST"
|
||||||
});
|
});
|
||||||
|
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
isLogedIn.value = true;
|
if (res.ok) {
|
||||||
displayName.value = body.displayname;
|
isLogedIn.value = true;
|
||||||
route.push("/");
|
displayName.value = body.displayname;
|
||||||
|
route.push("/");
|
||||||
|
} else {
|
||||||
|
console.log(body.error);
|
||||||
|
isLogedIn.value = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<template>
|
||||||
|
|
||||||
|
</template>
|
||||||
|
<script setup>
|
||||||
|
import { onMounted } from 'vue';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
import { displayName, isLogedIn } from '../global';
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await fetch("/php/user/logout.php");
|
||||||
|
isLogedIn.value = false;
|
||||||
|
displayName.value = "";
|
||||||
|
router.push("/login");
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user