mirror of
https://github.com/rommapp/romm.git
synced 2026-12-05 05:07:31 +01:00
front authentication poc
This commit is contained in:
@@ -295,3 +295,4 @@ Games can be tagged with region, revision or other tags using parenthesis in the
|
||||
# 🎖 Credits
|
||||
|
||||
* Pc icon support - <a href="https://www.flaticon.com/free-icons/keyboard-and-mouse" title="Keyboard and mouse icons">Keyboard and mouse icons created by Flat Icons - Flaticon</a>
|
||||
* Login page background wallpaper - <a href="https://www.freepik.com/free-vector/colorful-futuristic-background-with-shiny-particles_9260185.htm#query=gaming%20background&position=29&from_view=keyword&track=ais">Image by pikisuperstar</a> on Freepik
|
||||
|
||||
BIN
frontend/assets/login_bg.jpg
Normal file
BIN
frontend/assets/login_bg.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 231 KiB |
@@ -1,14 +1,21 @@
|
||||
<script setup>
|
||||
import { ref, inject, onMounted } from "vue";
|
||||
import { ref, inject, onMounted, onBeforeUpdate, nextTick } from "vue";
|
||||
import { useRouter, useRoute } from "vue-router";
|
||||
import { useTheme, useDisplay } from "vuetify";
|
||||
import { fetchPlatformsApi } from "@/services/api.js";
|
||||
import storePlatforms from "@/stores/platforms.js";
|
||||
import storeScanning from "@/stores/scanning.js";
|
||||
import Login from "@/views/Login.vue";
|
||||
import Drawer from "@/components/Drawer/Base.vue";
|
||||
import AppBar from "@/components/AppBar/Base.vue";
|
||||
import Notification from "@/components/Notification.vue";
|
||||
|
||||
// Props
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const logged = ref(
|
||||
localStorage.getItem("login") === "true"
|
||||
); /* TODO: implement authentication session logic */
|
||||
const platforms = storePlatforms();
|
||||
const scanning = storeScanning();
|
||||
const refreshPlatforms = ref(false);
|
||||
@@ -18,6 +25,11 @@ useTheme().global.name.value = localStorage.getItem("theme") || "rommDark";
|
||||
|
||||
// Event listeners bus
|
||||
const emitter = inject("emitter");
|
||||
emitter.on("login", (isLogged) => {
|
||||
router.isReady();
|
||||
logged.value = isLogged;
|
||||
});
|
||||
|
||||
emitter.on("refreshPlatforms", async () => {
|
||||
try {
|
||||
const { data } = await fetchPlatformsApi();
|
||||
@@ -33,39 +45,55 @@ emitter.on("refreshGallery", () => {
|
||||
refreshGallery.value = !refreshGallery.value;
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const { data } = await fetchPlatformsApi();
|
||||
platforms.set(data);
|
||||
} catch (error) {
|
||||
console.error("Couldn't fetch platforms:", error);
|
||||
async function checkLogin() {
|
||||
if (logged.value) {
|
||||
try {
|
||||
const { data } = await fetchPlatformsApi();
|
||||
platforms.set(data);
|
||||
} catch (error) {
|
||||
console.error("Couldn't fetch platforms:", error);
|
||||
}
|
||||
} else {
|
||||
await router.push("/login");
|
||||
}
|
||||
}
|
||||
onMounted(async () => {
|
||||
await checkLogin();
|
||||
});
|
||||
onBeforeUpdate(async () => {
|
||||
await checkLogin();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<v-app>
|
||||
<notification class="mt-6" />
|
||||
<template v-if="logged">
|
||||
<v-app>
|
||||
<notification class="mt-6" />
|
||||
|
||||
<v-progress-linear
|
||||
id="scan-progress-bar"
|
||||
color="rommAccent1"
|
||||
:active="scanning.value"
|
||||
:indeterminate="true"
|
||||
absolute
|
||||
fixed
|
||||
/>
|
||||
<v-progress-linear
|
||||
id="scan-progress-bar"
|
||||
color="rommAccent1"
|
||||
:active="scanning.value"
|
||||
:indeterminate="true"
|
||||
absolute
|
||||
fixed
|
||||
/>
|
||||
|
||||
<drawer :key="refreshPlatforms" />
|
||||
<drawer :key="refreshPlatforms" />
|
||||
|
||||
<app-bar v-if="mdAndDown" />
|
||||
<app-bar v-if="mdAndDown" />
|
||||
|
||||
<v-main>
|
||||
<v-container id="main-container" class="pa-1" fluid>
|
||||
<router-view :key="refreshGallery" />
|
||||
</v-container>
|
||||
</v-main>
|
||||
</v-app>
|
||||
<v-main>
|
||||
<v-container id="main-container" class="pa-1" fluid>
|
||||
<router-view :key="refreshGallery" />
|
||||
</v-container>
|
||||
</v-main>
|
||||
</v-app>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<login />
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -19,6 +19,12 @@ emitter.on("toggleDrawerRail", () => {
|
||||
rail.value = !rail.value;
|
||||
localStorage.setItem("rail", rail.value);
|
||||
});
|
||||
|
||||
function logout() {
|
||||
/* TODO: implement logout logic */
|
||||
localStorage.setItem("login", false);
|
||||
emitter.emit("login", false);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -29,10 +35,10 @@ emitter.on("toggleDrawerRail", () => {
|
||||
rail-width="145"
|
||||
elevation="0"
|
||||
>
|
||||
<v-list v-model:opened="open">
|
||||
<v-list v-model:opened="open" class="pa-0">
|
||||
<router-link to="/">
|
||||
<v-list-item class="justify-center pa-0">
|
||||
<v-img src="/assets/isotipo.svg" width="70" class="home-btn" />
|
||||
<v-img src="/assets/isotipo.svg" class="home-btn ma-2" />
|
||||
</v-list-item>
|
||||
</router-link>
|
||||
|
||||
@@ -124,6 +130,19 @@ emitter.on("toggleDrawerRail", () => {
|
||||
>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item
|
||||
class="drawer-item bg-terciary"
|
||||
@click="logout()"
|
||||
>
|
||||
<span class="text-body-2 text-truncate">{{
|
||||
rail ? "" : "Logout"
|
||||
}}</span>
|
||||
<template v-slot:prepend>
|
||||
<v-avatar :rounded="0" size="40"
|
||||
><v-icon>mdi-logout-variant</v-icon></v-avatar
|
||||
>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</v-list-group>
|
||||
</v-list>
|
||||
|
||||
@@ -136,8 +155,7 @@ emitter.on("toggleDrawerRail", () => {
|
||||
|
||||
<style scoped>
|
||||
.home-btn {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
width: 70px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ import { createRouter, createWebHistory } from "vue-router";
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: "/login",
|
||||
component: () => import("@/views/Login.vue"),
|
||||
path: "/",
|
||||
component: () => import("@/views/Home.vue"),
|
||||
},
|
||||
{
|
||||
path: "/",
|
||||
path: "/login",
|
||||
component: () => import("@/views/Home.vue"),
|
||||
},
|
||||
{
|
||||
|
||||
62
frontend/src/views/Login.vue
Normal file
62
frontend/src/views/Login.vue
Normal file
@@ -0,0 +1,62 @@
|
||||
<script setup>
|
||||
import { inject, onMounted } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
const emitter = inject("emitter");
|
||||
const router = useRouter();
|
||||
|
||||
async function login() {
|
||||
/* TODO: implement login logic */
|
||||
localStorage.setItem("login", true);
|
||||
emitter.emit("login", true);
|
||||
await router.push("/");
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span class="bg"></span>
|
||||
<v-row class="pa-2" no-gutters>
|
||||
<v-img src="/assets/isotipo.svg" class="login-logo ma-16" />
|
||||
</v-row>
|
||||
<v-row class="pa-2" no-gutters>
|
||||
<v-spacer />
|
||||
<v-col cols="12" xs="12" sm="10" md="10" lg="2">
|
||||
<v-text-field
|
||||
@keyup.enter="login()"
|
||||
type="text"
|
||||
label="username"
|
||||
variant="underlined"
|
||||
></v-text-field>
|
||||
<v-text-field
|
||||
@keyup.enter="login()"
|
||||
type="password"
|
||||
label="password"
|
||||
variant="underlined"
|
||||
></v-text-field>
|
||||
</v-col>
|
||||
<v-spacer />
|
||||
</v-row>
|
||||
|
||||
<v-row class="justify-center" no-gutters>
|
||||
<v-btn @click="login()" rounded="0" class="bg-terciary" >Login</v-btn>
|
||||
</v-row>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
.login-logo {
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
}
|
||||
.bg {
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
background: url("/assets/login_bg.jpg") no-repeat center center;
|
||||
background-size: cover;
|
||||
transform: scale(1);
|
||||
/* -webkit-filter: blur(3px);
|
||||
filter: blur(3px); */
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user