Work on login
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
$servername = getenv('DB_HOSTNAME');
|
$servername = $_ENV['DB_HOSTNAME'];
|
||||||
$username = getenv('DB_USERNAME');
|
$username = $_ENV['DB_USERNAME'];
|
||||||
$password = getenv('DB_PASS');
|
$password = $_ENV['DB_PASS'];
|
||||||
$dbname = getenv('DB_NAME');
|
$dbname = $_ENV['DB_NAME'];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
|
$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_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 json_encode(["error" => "error.connect.faild"]);
|
echo json_encode(["error" => "error.connect.faild", "exc" => $e->getMessage()]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-3
@@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
function hasPermission(string $resourceName, string $actionName): bool
|
function hasPermission(string $resourceName, string $actionName)
|
||||||
{
|
{
|
||||||
global $conn;
|
global $conn;
|
||||||
|
|
||||||
if(!isset($_SESSION['id'])){
|
if(!isset($_SESSION['id'])){
|
||||||
return false;
|
http_response_code(401);
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "
|
$sql = "
|
||||||
@@ -28,5 +29,8 @@ function hasPermission(string $resourceName, string $actionName): bool
|
|||||||
|
|
||||||
$result = $stmt->fetch();
|
$result = $stmt->fetch();
|
||||||
|
|
||||||
return ((int) $result['permission_count']) > 0;
|
if(((int) $result['permission_count']) <= 0){
|
||||||
|
http_response_code(403);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (!isset($_SESSION['id'])) {
|
||||||
|
http_response_code(401);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
http_response_code(200);
|
||||||
|
echo 'ok';
|
||||||
+24
-3
@@ -2,6 +2,24 @@
|
|||||||
|
|
||||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/auto.php';
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/auto/auto.php';
|
||||||
|
|
||||||
|
if ($_ENV['DEV_EMAIL']) {
|
||||||
|
$email = $_ENV['DEV_EMAIL'];
|
||||||
|
$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;
|
use LdapRecord\Connection;
|
||||||
$nimrodLDAP = new Connection([
|
$nimrodLDAP = new Connection([
|
||||||
'hosts' => [getenv('LDAP_HOST')],
|
'hosts' => [getenv('LDAP_HOST')],
|
||||||
@@ -61,8 +79,8 @@ $find->execute([':email' => $email]);
|
|||||||
$obstojeciUporabnik = $find->fetch();
|
$obstojeciUporabnik = $find->fetch();
|
||||||
|
|
||||||
if ($obstojeciUporabnik) {
|
if ($obstojeciUporabnik) {
|
||||||
$update = $conn->prepare("UPDATE users SET display_name = :display_name WHERE user_id = :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']]);
|
//$update->execute([':display_name' => $uporabnik, ':user_id' => $obstojeciUporabnik['user_id']]);
|
||||||
|
|
||||||
$_SESSION['id'] = $obstojeciUporabnik['user_id'];
|
$_SESSION['id'] = $obstojeciUporabnik['user_id'];
|
||||||
$_SESSION['username'] = $obstojeciUporabnik['username'];
|
$_SESSION['username'] = $obstojeciUporabnik['username'];
|
||||||
@@ -76,4 +94,7 @@ if ($obstojeciUporabnik) {
|
|||||||
$_SESSION['displayname'] = $uporabnik;
|
$_SESSION['displayname'] = $uporabnik;
|
||||||
$_SESSION['email'] = $email;
|
$_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);
|
||||||
Vendored
+15
@@ -38,6 +38,13 @@ declare module 'vue-router/auto-routes' {
|
|||||||
Record<never, never>,
|
Record<never, never>,
|
||||||
| never
|
| never
|
||||||
>,
|
>,
|
||||||
|
'/login': RouteRecordInfo<
|
||||||
|
'/login',
|
||||||
|
'/login',
|
||||||
|
Record<never, never>,
|
||||||
|
Record<never, never>,
|
||||||
|
| never
|
||||||
|
>,
|
||||||
'/settings': RouteRecordInfo<
|
'/settings': RouteRecordInfo<
|
||||||
'/settings',
|
'/settings',
|
||||||
'/settings',
|
'/settings',
|
||||||
@@ -88,6 +95,14 @@ declare module 'vue-router/auto-routes' {
|
|||||||
pathParamNames:
|
pathParamNames:
|
||||||
| never
|
| never
|
||||||
}
|
}
|
||||||
|
'vue/routes/login.vue': {
|
||||||
|
routes:
|
||||||
|
| '/login'
|
||||||
|
views:
|
||||||
|
| never
|
||||||
|
pathParamNames:
|
||||||
|
| never
|
||||||
|
}
|
||||||
'vue/routes/settings.vue': {
|
'vue/routes/settings.vue': {
|
||||||
routes:
|
routes:
|
||||||
| '/settings'
|
| '/settings'
|
||||||
|
|||||||
+2
-3
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="is-flex">
|
<div class="is-flex">
|
||||||
<Sidebar />
|
<Sidebar v-if="isLogedIn"/>
|
||||||
<main class="p-5 is-flex-grow-1">
|
<main class="p-5 is-flex-grow-1">
|
||||||
<RouterView />
|
<RouterView />
|
||||||
</main>
|
</main>
|
||||||
@@ -8,11 +8,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useI18n } from 'vue-i18n'
|
|
||||||
import { applyTheme } from '@/components/theme';
|
import { applyTheme } from '@/components/theme';
|
||||||
import Sidebar from '@/components/Sidebar.vue';
|
import Sidebar from '@/components/Sidebar.vue';
|
||||||
|
import { isLogedIn } from './global';
|
||||||
|
|
||||||
applyTheme();
|
applyTheme();
|
||||||
|
|
||||||
const { t } = useI18n();
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
</RouterLink>
|
</RouterLink>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<p class="menu-label" v-if="!collapsed">{{ displayName }}</p>
|
||||||
</aside>
|
</aside>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { RouterLink } from 'vue-router';
|
import { RouterLink } from 'vue-router';
|
||||||
|
import { displayName } from '@/global.js';
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,16 @@
|
|||||||
<div class="dropdown is-hoverable">
|
<div class="dropdown is-hoverable">
|
||||||
<div class="dropdown-trigger">
|
<div class="dropdown-trigger">
|
||||||
<button class="button">
|
<button class="button">
|
||||||
<span>Barvna tema</span>
|
<span>{{ t('userSettings.themeSelect') }}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="dropdown-menu">
|
<div class="dropdown-menu">
|
||||||
<div class="dropdown-content">
|
<div class="dropdown-content">
|
||||||
<button class="dropdown-item" @click.prevent="setTheme('light')">
|
<button class="dropdown-item" @click.prevent="setTheme('light')">
|
||||||
Svetlo
|
{{ t('userSettings.light') }}
|
||||||
</button>
|
</button>
|
||||||
<button class="dropdown-item" @click.prevent="setTheme('dark')">
|
<button class="dropdown-item" @click.prevent="setTheme('dark')">
|
||||||
Temno
|
{{ t('userSettings.dark') }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -19,5 +19,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
import { setTheme } from './theme';
|
import { setTheme } from './theme';
|
||||||
|
const {t} = useI18n();
|
||||||
</script>
|
</script>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { ref } from "vue";
|
||||||
|
|
||||||
|
|
||||||
|
export const isLogedIn = ref(false);
|
||||||
|
export const displayName = ref("");
|
||||||
+8
-3
@@ -1,4 +1,9 @@
|
|||||||
{
|
{
|
||||||
|
"userSettings":{
|
||||||
|
"themeSelect": "Select theme",
|
||||||
|
"light":"Light",
|
||||||
|
"dark":"Dark"
|
||||||
|
},
|
||||||
"menu": {
|
"menu": {
|
||||||
"settings": "Settings",
|
"settings": "Settings",
|
||||||
"userSettings": "User settings",
|
"userSettings": "User settings",
|
||||||
@@ -18,8 +23,8 @@
|
|||||||
"search": "Search",
|
"search": "Search",
|
||||||
"loading": "Loading..."
|
"loading": "Loading..."
|
||||||
},
|
},
|
||||||
"app": {
|
"login": {
|
||||||
"hello": "HELLO",
|
"username": "Username",
|
||||||
"world": "WORLD"
|
"password": "Password"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+12
-3
@@ -1,9 +1,18 @@
|
|||||||
{
|
{
|
||||||
|
"userSettings": {
|
||||||
|
"themeSelect": "Izberi temo",
|
||||||
|
"light": "Svetlo",
|
||||||
|
"dark": "Temno"
|
||||||
|
},
|
||||||
"menu": {
|
"menu": {
|
||||||
"settings": "Nastavitve",
|
"settings": "Nastavitve",
|
||||||
"userSettings": "Uporabniške nastavitve",
|
"userSettings": "Uporabniške nastavitve",
|
||||||
"dashboard": "Nadzorna plošča"
|
"dashboard": "Nadzorna plošča"
|
||||||
},
|
},
|
||||||
|
"settings": {
|
||||||
|
"users": "Uporabni",
|
||||||
|
"groups": "Skupine"
|
||||||
|
},
|
||||||
"common": {
|
"common": {
|
||||||
"save": "Shrani",
|
"save": "Shrani",
|
||||||
"cancel": "Prekliči",
|
"cancel": "Prekliči",
|
||||||
@@ -14,8 +23,8 @@
|
|||||||
"search": "Iskanje",
|
"search": "Iskanje",
|
||||||
"loading": "Nalaganje..."
|
"loading": "Nalaganje..."
|
||||||
},
|
},
|
||||||
"app": {
|
"login": {
|
||||||
"hello": "ZDRAVO",
|
"username": "Uporabniško ime",
|
||||||
"world": "SVET"
|
"password": "Geslo"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ import { i18n, setLocale, initialLocale } from './i18n.js'
|
|||||||
import './css/all.css'
|
import './css/all.css'
|
||||||
|
|
||||||
import App from './app.vue'
|
import App from './app.vue'
|
||||||
|
import { isLogedIn } from './global.js'
|
||||||
|
|
||||||
await setLocale(initialLocale())
|
await setLocale(initialLocale())
|
||||||
|
|
||||||
@@ -18,5 +19,12 @@ if (import.meta.hot) {
|
|||||||
handleHotUpdate(router)
|
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')
|
createApp(App).use(router).use(i18n).mount('#app')
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<template>
|
||||||
|
<div class="columns is-vcentered" style="height: 50rem;">
|
||||||
|
<div class="column is-2 is-offset-5">
|
||||||
|
<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 { ref } from 'vue';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { displayName, isLogedIn } from '../global';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
const { t } = useI18n();
|
||||||
|
const route = useRouter();
|
||||||
|
|
||||||
|
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": mes,
|
||||||
|
"method": "POST"
|
||||||
|
});
|
||||||
|
const body = await res.json();
|
||||||
|
isLogedIn.value = true;
|
||||||
|
displayName.value = body.displayname;
|
||||||
|
route.push("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user