Compare commits
2
Commits
abf00ac401
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
937c06ef8d | ||
|
|
fb09048e45 |
+11
-1
@@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
$servername = getenv('DB_HOSTNAME');
|
||||
$username = getenv('DB_USERNAME');
|
||||
$password = getenv('DB_PASS');
|
||||
$dbname = getenv('DB_NAME');
|
||||
$servername = $_ENV['DB_HOSTNAME'];
|
||||
$username = $_ENV['DB_USERNAME'];
|
||||
$password = $_ENV['DB_PASS'];
|
||||
$dbname = $_ENV['DB_NAME'];
|
||||
|
||||
try {
|
||||
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
|
||||
@@ -11,7 +11,7 @@ try {
|
||||
$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
||||
} catch(PDOException $e) {
|
||||
echo json_encode(["error" => "error.connect.faild"]);
|
||||
echo json_encode(["error" => "error.connect.faild", "exc" => $e->getMessage()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
+7
-3
@@ -1,11 +1,12 @@
|
||||
<?php
|
||||
|
||||
function hasPermission(string $resourceName, string $actionName): bool
|
||||
function hasPermission(string $resourceName, string $actionName)
|
||||
{
|
||||
global $conn;
|
||||
|
||||
if(!isset($_SESSION['id'])){
|
||||
return false;
|
||||
http_response_code(401);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
@@ -28,5 +29,8 @@ function hasPermission(string $resourceName, string $actionName): bool
|
||||
|
||||
$result = $stmt->fetch();
|
||||
|
||||
return ((int) $result['permission_count']) > 0;
|
||||
if(((int) $result['permission_count']) <= 0){
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/auto.php';
|
||||
|
||||
if (!isset($_SESSION['id'])) {
|
||||
http_response_code(401);
|
||||
exit;
|
||||
}
|
||||
|
||||
http_response_code(200);
|
||||
echo json_encode([
|
||||
"res" => "res.user.login.true",
|
||||
"displayname" => $_SESSION['displayname']
|
||||
]);
|
||||
+39
-13
@@ -2,46 +2,68 @@
|
||||
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/auto.php';
|
||||
|
||||
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();
|
||||
|
||||
$_SESSION['id'] = $obstojeciUporabnik['user_id'];
|
||||
$_SESSION['username'] = $obstojeciUporabnik['username'];
|
||||
$_SESSION['displayname'] = $obstojeciUporabnik['display_name'];
|
||||
$_SESSION['email'] = $email;
|
||||
|
||||
echo json_encode([
|
||||
"res" => "res.user.login.true",
|
||||
"displayname" => $_SESSION['displayname']
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$emailUserja = $LUser['userprincipalname'][0];
|
||||
$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;
|
||||
}
|
||||
|
||||
$vGrupah = $LUser['memberof'];
|
||||
$dGrupe = [
|
||||
'cn=Nimrod_Web,ou=Nimrod OU,dc=nimrod,dc=local',
|
||||
$dGrupe = [
|
||||
'cn=Nimrod_Web,ou=Nimrod OU,dc=nimrod,dc=local',
|
||||
];
|
||||
|
||||
$razlikaGrup = array_intersect(
|
||||
@@ -49,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;
|
||||
}
|
||||
@@ -61,8 +84,8 @@ $find->execute([':email' => $email]);
|
||||
$obstojeciUporabnik = $find->fetch();
|
||||
|
||||
if ($obstojeciUporabnik) {
|
||||
$update = $conn->prepare("UPDATE users SET display_name = :display_name WHERE user_id = :user_id");
|
||||
$update->execute([':display_name' => $uporabnik, ':user_id' => $obstojeciUporabnik['user_id']]);
|
||||
//$update = $conn->prepare("UPDATE users SET display_name = :display_name WHERE user_id = :user_id");
|
||||
//$update->execute([':display_name' => $uporabnik, ':user_id' => $obstojeciUporabnik['user_id']]);
|
||||
|
||||
$_SESSION['id'] = $obstojeciUporabnik['user_id'];
|
||||
$_SESSION['username'] = $obstojeciUporabnik['username'];
|
||||
@@ -76,4 +99,7 @@ if ($obstojeciUporabnik) {
|
||||
$_SESSION['displayname'] = $uporabnik;
|
||||
$_SESSION['email'] = $email;
|
||||
|
||||
echo json_encode(["res" => "res.user.login.true"]);
|
||||
echo json_encode([
|
||||
"res" => "res.user.login.true",
|
||||
"displayname" => $_SESSION['displayname']
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/auto.php';
|
||||
|
||||
|
||||
$sql = "SELECT username, email, group_id FROM users;";
|
||||
|
||||
$res = $conn->query($sql);
|
||||
|
||||
echo json_encode($res);
|
||||
@@ -1,3 +1,4 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_destroy();
|
||||
echo json_encode(["res" => "res.user.loginout.true"]);
|
||||
Vendored
+30
@@ -38,6 +38,20 @@ declare module 'vue-router/auto-routes' {
|
||||
Record<never, never>,
|
||||
| never
|
||||
>,
|
||||
'/login': RouteRecordInfo<
|
||||
'/login',
|
||||
'/login',
|
||||
Record<never, never>,
|
||||
Record<never, never>,
|
||||
| never
|
||||
>,
|
||||
'/logout': RouteRecordInfo<
|
||||
'/logout',
|
||||
'/logout',
|
||||
Record<never, never>,
|
||||
Record<never, never>,
|
||||
| never
|
||||
>,
|
||||
'/settings': RouteRecordInfo<
|
||||
'/settings',
|
||||
'/settings',
|
||||
@@ -88,6 +102,22 @@ declare module 'vue-router/auto-routes' {
|
||||
pathParamNames:
|
||||
| never
|
||||
}
|
||||
'vue/routes/login.vue': {
|
||||
routes:
|
||||
| '/login'
|
||||
views:
|
||||
| never
|
||||
pathParamNames:
|
||||
| never
|
||||
}
|
||||
'vue/routes/logout.vue': {
|
||||
routes:
|
||||
| '/logout'
|
||||
views:
|
||||
| never
|
||||
pathParamNames:
|
||||
| never
|
||||
}
|
||||
'vue/routes/settings.vue': {
|
||||
routes:
|
||||
| '/settings'
|
||||
|
||||
+2
-3
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="is-flex">
|
||||
<Sidebar />
|
||||
<Sidebar v-if="isLogedIn"/>
|
||||
<main class="p-5 is-flex-grow-1">
|
||||
<RouterView />
|
||||
</main>
|
||||
@@ -8,11 +8,10 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { applyTheme } from '@/components/theme';
|
||||
import Sidebar from '@/components/Sidebar.vue';
|
||||
import { isLogedIn } from './global';
|
||||
|
||||
applyTheme();
|
||||
|
||||
const { t } = useI18n();
|
||||
</script>
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
</RouterLink>
|
||||
</li>
|
||||
</ul>
|
||||
<p class="menu-label" v-if="!collapsed">{{ displayName }}</p>
|
||||
</aside>
|
||||
</template>
|
||||
|
||||
@@ -30,6 +31,7 @@
|
||||
import { ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { RouterLink } from 'vue-router';
|
||||
import { displayName } from '@/global.js';
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -49,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' },
|
||||
];
|
||||
</script>
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
<div class="dropdown is-hoverable">
|
||||
<div class="dropdown-trigger">
|
||||
<button class="button">
|
||||
<span>Barvna tema</span>
|
||||
<span>{{ t('userSettings.themeSelect') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="dropdown-menu">
|
||||
<div class="dropdown-content">
|
||||
<button class="dropdown-item" @click.prevent="setTheme('light')">
|
||||
Svetlo
|
||||
{{ t('userSettings.light') }}
|
||||
</button>
|
||||
<button class="dropdown-item" @click.prevent="setTheme('dark')">
|
||||
Temno
|
||||
{{ t('userSettings.dark') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -19,5 +19,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { setTheme } from './theme';
|
||||
const {t} = useI18n();
|
||||
</script>
|
||||
@@ -0,0 +1,5 @@
|
||||
import { ref } from "vue";
|
||||
|
||||
|
||||
export const isLogedIn = ref(false);
|
||||
export const displayName = ref("");
|
||||
+13
-7
@@ -1,12 +1,18 @@
|
||||
{
|
||||
"userSettings": {
|
||||
"themeSelect": "Select theme",
|
||||
"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",
|
||||
@@ -18,8 +24,8 @@
|
||||
"search": "Search",
|
||||
"loading": "Loading..."
|
||||
},
|
||||
"app": {
|
||||
"hello": "HELLO",
|
||||
"world": "WORLD"
|
||||
"login": {
|
||||
"username": "Username",
|
||||
"password": "Password"
|
||||
}
|
||||
}
|
||||
+14
-4
@@ -1,8 +1,18 @@
|
||||
{
|
||||
"userSettings": {
|
||||
"themeSelect": "Izberi temo",
|
||||
"light": "Svetlo",
|
||||
"dark": "Temno"
|
||||
},
|
||||
"menu": {
|
||||
"settings": "Nastavitve",
|
||||
"userSettings": "Uporabniške nastavitve",
|
||||
"dashboard": "Nadzorna plošča"
|
||||
"dashboard": "Nadzorna plošča",
|
||||
"logout": "Odjava"
|
||||
},
|
||||
"settings": {
|
||||
"users": "Uporabni",
|
||||
"groups": "Skupine"
|
||||
},
|
||||
"common": {
|
||||
"save": "Shrani",
|
||||
@@ -14,8 +24,8 @@
|
||||
"search": "Iskanje",
|
||||
"loading": "Nalaganje..."
|
||||
},
|
||||
"app": {
|
||||
"hello": "ZDRAVO",
|
||||
"world": "SVET"
|
||||
"login": {
|
||||
"username": "Uporabniško ime",
|
||||
"password": "Geslo"
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { i18n, setLocale, initialLocale } from './i18n.js'
|
||||
import './css/all.css'
|
||||
|
||||
import App from './app.vue'
|
||||
import { isLogedIn } from './global.js'
|
||||
|
||||
await setLocale(initialLocale())
|
||||
|
||||
@@ -18,5 +19,12 @@ if (import.meta.hot) {
|
||||
handleHotUpdate(router)
|
||||
}
|
||||
|
||||
router.beforeEach(async (to, from) => {
|
||||
if (!isLogedIn.value && to.name != '/login' ) {
|
||||
// redirect the user to the login page
|
||||
return { name: '/login' }
|
||||
}
|
||||
})
|
||||
|
||||
createApp(App).use(router).use(i18n).mount('#app')
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
<template>
|
||||
<div class="columns is-vcentered" style="height: 50rem;">
|
||||
<div class="column is-4 is-offset-4">
|
||||
<form @submit.prevent="logIn">
|
||||
<div class="field">
|
||||
<label class="label">{{ t('login.username') }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" v-model="userName">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">{{ t('login.password') }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="password" v-model="password">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<button class="button is-primary">{{ t('common.confirm') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { displayName, isLogedIn } from '../global';
|
||||
import { useRouter } from 'vue-router';
|
||||
const { t } = useI18n();
|
||||
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 password = ref();
|
||||
|
||||
async function logIn() {
|
||||
const mes = {
|
||||
"username": userName.value,
|
||||
"pass": password.value
|
||||
}
|
||||
const res = await fetch("/php/user/ldapLogin.php", {
|
||||
"body": JSON.stringify(mes),
|
||||
"method": "POST"
|
||||
});
|
||||
|
||||
const body = await res.json();
|
||||
if (res.ok) {
|
||||
isLogedIn.value = true;
|
||||
displayName.value = body.displayname;
|
||||
route.push("/");
|
||||
} else {
|
||||
console.log(body.error);
|
||||
isLogedIn.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
</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