backup
This commit is contained in:
11
frontend/app/services/BackendURL.js
Normal file
11
frontend/app/services/BackendURL.js
Normal file
@@ -0,0 +1,11 @@
|
||||
var backendUrl = ''
|
||||
if (import.meta.env.PROD) {
|
||||
backendUrl = 'https://api.aranroig.com/';
|
||||
} else {
|
||||
backendUrl = 'http://localhost:5000/'
|
||||
}
|
||||
|
||||
|
||||
export {
|
||||
backendUrl
|
||||
};
|
||||
12
frontend/app/services/Content.js
Normal file
12
frontend/app/services/Content.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
const ShowContent = ref(false);
|
||||
|
||||
function SetShowContent(value) {
|
||||
ShowContent.value = value;
|
||||
}
|
||||
|
||||
export {
|
||||
ShowContent,
|
||||
SetShowContent
|
||||
}
|
||||
3
frontend/app/services/Emitter.js
Normal file
3
frontend/app/services/Emitter.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import mitt from 'mitt'
|
||||
|
||||
export const emitter = mitt();
|
||||
21
frontend/app/services/Server.js
Normal file
21
frontend/app/services/Server.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import axios from 'axios';
|
||||
|
||||
import { backendUrl } from './BackendURL';
|
||||
|
||||
const server = axios.create({
|
||||
baseURL: backendUrl,
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
}
|
||||
});
|
||||
|
||||
// Attach token dynamically on each request via interceptor
|
||||
server.interceptors.request.use((config) => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
export default () => server;
|
||||
9
frontend/app/services/Toaster.js
Normal file
9
frontend/app/services/Toaster.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import { emitter } from './Emitter';
|
||||
|
||||
function DisplayToast(color, text, duration = 1000){
|
||||
emitter.emit("toast", {color, text, duration});
|
||||
}
|
||||
|
||||
export {
|
||||
DisplayToast,
|
||||
}
|
||||
80
frontend/app/services/User.js
Normal file
80
frontend/app/services/User.js
Normal file
@@ -0,0 +1,80 @@
|
||||
import { ref } from 'vue';
|
||||
import Server from './Server';
|
||||
|
||||
const UserStatus = ref(0);
|
||||
|
||||
function parseJwt(token) {
|
||||
return JSON.parse(atob(token.split('.')[1]));
|
||||
}
|
||||
|
||||
function SetUser(token){
|
||||
localStorage.setItem('token', token);
|
||||
UserStatus.value = 1;
|
||||
}
|
||||
|
||||
async function HasAdmin(){
|
||||
let response = await Server().get('/user/has-admin');
|
||||
return response.data.status != "init";
|
||||
}
|
||||
|
||||
async function SetUserSetting(key, value){
|
||||
let user = GetUser();
|
||||
if(!user.settings) user.settings = {};
|
||||
user.settings[key] = value;
|
||||
const response = await Server().post('/user/update-settings', { settings: user.settings });
|
||||
return response.data.settings;
|
||||
}
|
||||
|
||||
async function GetUserSetting(key){
|
||||
const response = await Server().get('/user/get-settings');
|
||||
if (response.data.settings)
|
||||
return response.data.settings[key];
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function GetUser(){
|
||||
const token = localStorage.getItem('token');
|
||||
|
||||
if(token){
|
||||
const data = parseJwt(token);
|
||||
|
||||
// Check if token is expired
|
||||
const now = Date.now() / 1000;
|
||||
if(now > data.exp){
|
||||
LogoutUser();
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function IsAdmin(){
|
||||
const user = GetUser();
|
||||
if(user){
|
||||
return user.admin;
|
||||
}
|
||||
}
|
||||
|
||||
function LoadUser(){
|
||||
const token = localStorage.getItem('token');
|
||||
if(token) UserStatus.value = 1;
|
||||
}
|
||||
|
||||
function LogoutUser(){
|
||||
localStorage.removeItem("token");
|
||||
UserStatus.value = 0;
|
||||
}
|
||||
|
||||
export {
|
||||
UserStatus,
|
||||
GetUser,
|
||||
SetUser,
|
||||
LoadUser,
|
||||
IsAdmin,
|
||||
LogoutUser,
|
||||
HasAdmin,
|
||||
GetUserSetting,
|
||||
SetUserSetting
|
||||
}
|
||||
@@ -3,22 +3,29 @@ import { ref } from 'vue'
|
||||
const windows = ref([]);
|
||||
|
||||
import LoginWindow from '~/components/windows/LoginWindow.vue';
|
||||
import RegisterWindow from '~/components/windows/RegisterWindow.vue';
|
||||
import ExampleWindow from '~/components/windows/ExampleWindow.vue';
|
||||
|
||||
let windowMap = {
|
||||
login: LoginWindow
|
||||
login: LoginWindow,
|
||||
register: RegisterWindow,
|
||||
example: ExampleWindow
|
||||
};
|
||||
|
||||
async function InjectWindow(window_type, plugin, window_component) {
|
||||
let systemWidows = {};
|
||||
systemWidows[window_type] = (await import(`../../plugins/${plugin}/views/${window_component}.vue`)).default;
|
||||
windowMap = { ...windowMap, ...systemWidows };
|
||||
}
|
||||
|
||||
// Presets
|
||||
const defValues = {
|
||||
'example': {
|
||||
id: "example",
|
||||
title: "Example",
|
||||
close: () => ClearWindow('example')
|
||||
},
|
||||
'login': {
|
||||
id: 'login',
|
||||
title: 'Login',
|
||||
},
|
||||
'register': {
|
||||
id: 'register',
|
||||
title: 'Register'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +66,9 @@ function SetupHandle(id, handle) {
|
||||
SetOnTop(id);
|
||||
});
|
||||
|
||||
// Move window listeners
|
||||
handler.addEventListener("mousedown", (event) => {
|
||||
if(win.noMove) return;
|
||||
draggingWindow = true;
|
||||
|
||||
let windowRect = currentWindow.getBoundingClientRect();
|
||||
@@ -67,8 +76,8 @@ function SetupHandle(id, handle) {
|
||||
offsetY = windowRect.top - event.clientY;
|
||||
})
|
||||
|
||||
// Move window listeners
|
||||
document.addEventListener("mousemove", (event) => {
|
||||
if(win.noMove) return;
|
||||
if (!draggingWindow) return;
|
||||
|
||||
if (event.clientX + offsetX < -currentWindow.getBoundingClientRect().width + 20) currentWindow.style.left = (-currentWindow.getBoundingClientRect().width + 20) + "px";
|
||||
@@ -81,6 +90,7 @@ function SetupHandle(id, handle) {
|
||||
})
|
||||
|
||||
document.addEventListener("mouseup", (event) => {
|
||||
if(win.noMove) return;
|
||||
draggingWindow = false;
|
||||
// ummm suposo que no pots tancar mentres mous?
|
||||
SaveWindowPos({ id, x: parseInt(currentWindow.style.left, 10), y: parseInt(currentWindow.style.top, 10) });
|
||||
@@ -126,6 +136,11 @@ function SetResizable(id, resizable) {
|
||||
win.resizable = resizable;
|
||||
}
|
||||
|
||||
function SetMovable(id, movable) {
|
||||
let win = GetWindowWithId(id);
|
||||
win.noMove = !movable;
|
||||
}
|
||||
|
||||
function SetSize(id, size) {
|
||||
let currentWindowId = "window-wrapper-" + id;
|
||||
let currentWindow = document.getElementById(currentWindowId);
|
||||
@@ -284,10 +299,10 @@ export {
|
||||
SetMaxSize,
|
||||
SetMinSize,
|
||||
SetPosition,
|
||||
SetMovable,
|
||||
ResetPosition,
|
||||
Windows,
|
||||
WindowMap,
|
||||
InjectWindow,
|
||||
ReloadRef,
|
||||
ClearWindows,
|
||||
CreateWindow,
|
||||
|
||||
Reference in New Issue
Block a user