mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 10:32:57 +01:00
Merge branch 'feature/user-own-edit' into feature/favs-collection
This commit is contained in:
@@ -8,6 +8,7 @@ from config import (
|
||||
)
|
||||
from endpoints.responses.heartbeat import HeartbeatResponse
|
||||
from fastapi import APIRouter
|
||||
from handler.database import db_user_handler
|
||||
from handler.filesystem import fs_platform_handler
|
||||
from handler.metadata.igdb_handler import IGDB_API_ENABLED
|
||||
from handler.metadata.moby_handler import MOBY_API_ENABLED
|
||||
@@ -27,6 +28,7 @@ def heartbeat() -> HeartbeatResponse:
|
||||
|
||||
return {
|
||||
"VERSION": get_version(),
|
||||
"SETUP_WIZARD": len(db_user_handler.get_admin_users()) == 0,
|
||||
"ANY_SOURCE_ENABLED": IGDB_API_ENABLED or MOBY_API_ENABLED,
|
||||
"STEAMGRIDDB_ENABLED": STEAMGRIDDB_API_ENABLED,
|
||||
"METADATA_SOURCES": {
|
||||
|
||||
@@ -23,6 +23,7 @@ class MetadataSourcesDict(TypedDict):
|
||||
|
||||
class HeartbeatResponse(TypedDict):
|
||||
VERSION: str
|
||||
SETUP_WIZARD: bool
|
||||
WATCHER: WatcherDict
|
||||
SCHEDULER: SchedulerDict
|
||||
ANY_SOURCE_ENABLED: bool
|
||||
|
||||
@@ -16,7 +16,10 @@ router = APIRouter()
|
||||
|
||||
|
||||
@protected_route(
|
||||
router.post, "/users", ["users.write"], status_code=status.HTTP_201_CREATED
|
||||
router.post,
|
||||
"/users",
|
||||
[] if len(db_user_handler.get_admin_users()) == 0 else ["users.write"],
|
||||
status_code=status.HTTP_201_CREATED,
|
||||
)
|
||||
def add_user(request: Request, username: str, password: str, role: str) -> UserSchema:
|
||||
"""Create user endpoint
|
||||
@@ -86,7 +89,7 @@ def get_user(request: Request, id: int) -> UserSchema:
|
||||
return user
|
||||
|
||||
|
||||
@protected_route(router.put, "/users/{id}", ["users.write"])
|
||||
@protected_route(router.put, "/users/{id}")
|
||||
def update_user(
|
||||
request: Request, id: int, form_data: Annotated[UserForm, Depends()]
|
||||
) -> UserSchema:
|
||||
@@ -105,17 +108,23 @@ def update_user(
|
||||
UserSchema: Updated user info
|
||||
"""
|
||||
|
||||
user = db_user_handler.get_user(id)
|
||||
if not user:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
db_user = db_user_handler.get_user(id)
|
||||
if not db_user:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="User not found"
|
||||
)
|
||||
|
||||
if not db_user.id == request.user.id:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Forbidden")
|
||||
|
||||
cleaned_data = {}
|
||||
|
||||
if form_data.username and form_data.username != user.username:
|
||||
if form_data.username and form_data.username != db_user.username:
|
||||
existing_user = db_user_handler.get_user_by_username(form_data.username.lower())
|
||||
if existing_user:
|
||||
raise HTTPException(
|
||||
status_code=400, detail="Username already in use by another user"
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Username already in use by another user",
|
||||
)
|
||||
|
||||
cleaned_data["username"] = form_data.username.lower()
|
||||
@@ -134,7 +143,7 @@ def update_user(
|
||||
cleaned_data["enabled"] = form_data.enabled # type: ignore[assignment]
|
||||
|
||||
if form_data.avatar is not None:
|
||||
user_avatar_path = fs_asset_handler.build_avatar_path(user=user)
|
||||
user_avatar_path = fs_asset_handler.build_avatar_path(user=db_user)
|
||||
file_location = f"{user_avatar_path}/{form_data.avatar.filename}"
|
||||
cleaned_data["avatar_path"] = file_location
|
||||
Path(f"{ASSETS_BASE_PATH}/{user_avatar_path}").mkdir(
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Final
|
||||
|
||||
from config import ROMM_AUTH_PASSWORD, ROMM_AUTH_SECRET_KEY, ROMM_AUTH_USERNAME
|
||||
from config import ROMM_AUTH_SECRET_KEY
|
||||
from exceptions.auth_exceptions import OAuthCredentialsException
|
||||
from fastapi import HTTPException, status
|
||||
from joserfc import jwt
|
||||
from joserfc.errors import BadSignatureError
|
||||
from joserfc.jwk import OctKey
|
||||
from passlib.context import CryptContext
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from starlette.requests import HTTPConnection
|
||||
|
||||
ALGORITHM: Final = "HS256"
|
||||
@@ -81,7 +80,7 @@ class AuthHandler:
|
||||
# Key exists therefore user is probably authenticated
|
||||
user = db_user_handler.get_user_by_username(username)
|
||||
if user is None:
|
||||
conn.session = {}
|
||||
conn.session.clear()
|
||||
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
@@ -89,29 +88,15 @@ class AuthHandler:
|
||||
)
|
||||
|
||||
if not user.enabled:
|
||||
conn.session = {}
|
||||
conn.session.clear()
|
||||
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN, detail="Inactive user"
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail=f"Inactive user {user.username}",
|
||||
)
|
||||
|
||||
return user
|
||||
|
||||
def create_default_admin_user(self):
|
||||
from handler.database import db_user_handler
|
||||
from models.user import Role, User
|
||||
|
||||
try:
|
||||
db_user_handler.add_user(
|
||||
User(
|
||||
username=ROMM_AUTH_USERNAME,
|
||||
hashed_password=self.get_password_hash(ROMM_AUTH_PASSWORD),
|
||||
role=Role.ADMIN,
|
||||
)
|
||||
)
|
||||
except IntegrityError:
|
||||
pass
|
||||
|
||||
|
||||
class OAuthHandler:
|
||||
def __init__(self) -> None:
|
||||
|
||||
@@ -66,23 +66,7 @@ async def test_get_current_active_user_from_session_disabled_user(editor_user: U
|
||||
await auth_handler.get_current_active_user_from_session(conn)
|
||||
except HTTPException as e:
|
||||
assert e.status_code == 403
|
||||
assert e.detail == "Inactive user"
|
||||
|
||||
|
||||
def test_create_default_admin_user():
|
||||
auth_handler.create_default_admin_user()
|
||||
|
||||
user = db_user_handler.get_user_by_username("test_admin")
|
||||
assert user.username == "test_admin"
|
||||
assert auth_handler.verify_password("test_admin_password", user.hashed_password)
|
||||
|
||||
users = db_user_handler.get_users()
|
||||
assert len(users) == 1
|
||||
|
||||
auth_handler.create_default_admin_user()
|
||||
|
||||
users = db_user_handler.get_users()
|
||||
assert len(users) == 1
|
||||
assert e.detail == "Inactive user test_editor"
|
||||
|
||||
|
||||
async def test_hybrid_auth_backend_session(editor_user: User):
|
||||
|
||||
@@ -34,4 +34,6 @@ class DBStatsHandler(DBBaseHandler):
|
||||
@begin_session
|
||||
def get_total_filesize(self, session: Session = None) -> int:
|
||||
"""Get the total filesize of all roms in the database, in bytes."""
|
||||
return session.scalar(select(func.sum(Rom.file_size_bytes)).select_from(Rom))
|
||||
return (
|
||||
session.scalar(select(func.sum(Rom.file_size_bytes)).select_from(Rom)) or 0
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from decorators.database import begin_session
|
||||
from models.user import Role, User
|
||||
from sqlalchemy import delete, select, update
|
||||
from sqlalchemy.exc import ProgrammingError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .base_handler import DBBaseHandler
|
||||
@@ -42,4 +43,10 @@ class DBUsersHandler(DBBaseHandler):
|
||||
|
||||
@begin_session
|
||||
def get_admin_users(self, session: Session = None) -> list[User]:
|
||||
return session.scalars(select(User).filter_by(role=Role.ADMIN)).all()
|
||||
try:
|
||||
return session.scalars(select(User).filter_by(role=Role.ADMIN)).all()
|
||||
except ProgrammingError as e:
|
||||
if "Table" in str(e.orig) and "doesn't exist" in str(e.orig):
|
||||
return []
|
||||
else:
|
||||
raise ProgrammingError from e
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import re
|
||||
import sys
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
import alembic.config
|
||||
import endpoints.sockets.scan # noqa
|
||||
@@ -26,27 +25,14 @@ from endpoints import (
|
||||
)
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from handler.auth import auth_handler
|
||||
from handler.auth.base_handler import ALGORITHM
|
||||
from handler.auth.hybrid_auth import HybridAuthBackend
|
||||
from handler.auth.middleware import CustomCSRFMiddleware, SessionMiddleware
|
||||
from handler.database import db_user_handler
|
||||
from handler.socket_handler import socket_handler
|
||||
from starlette.middleware.authentication import AuthenticationMiddleware
|
||||
from utils import get_version
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
if "pytest" not in sys.modules:
|
||||
# Create default admin user if no admin user exists
|
||||
if len(db_user_handler.get_admin_users()) == 0:
|
||||
auth_handler.create_default_admin_user()
|
||||
|
||||
yield
|
||||
|
||||
|
||||
app = FastAPI(title="RomM API", version=get_version(), lifespan=lifespan)
|
||||
app = FastAPI(title="RomM API", version=get_version())
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
|
||||
BIN
frontend/assets/scrappers/sgdb.png
Normal file
BIN
frontend/assets/scrappers/sgdb.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 146 B |
@@ -1,26 +1,54 @@
|
||||
<script setup lang="ts">
|
||||
import Notification from "@/components/common/Notification.vue";
|
||||
import api from "@/services/api/index";
|
||||
import userApi from "@/services/api/user";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import storeConfig from "@/stores/config";
|
||||
import storeHeartbeat from "@/stores/heartbeat";
|
||||
import storeNotifications from "@/stores/notifications";
|
||||
import Cookies from "js-cookie";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { onMounted } from "vue";
|
||||
import { onBeforeMount } from "vue";
|
||||
import router from "./plugins/router";
|
||||
|
||||
// Props
|
||||
const notificationStore = storeNotifications();
|
||||
const { notifications } = storeToRefs(notificationStore);
|
||||
const heartbeat = storeHeartbeat();
|
||||
const auth = storeAuth();
|
||||
const configStore = storeConfig();
|
||||
|
||||
onMounted(async () => {
|
||||
await api.get("/heartbeat").then(({ data: data }) => {
|
||||
heartbeat.set(data);
|
||||
});
|
||||
onBeforeMount(async () => {
|
||||
await api
|
||||
.get("/heartbeat")
|
||||
.then(async ({ data: data }) => {
|
||||
heartbeat.set(data);
|
||||
if (heartbeat.value.SETUP_WIZARD) {
|
||||
router.push({ name: "setup" });
|
||||
} else {
|
||||
await userApi
|
||||
.fetchCurrentUser()
|
||||
.then(({ data: user }) => {
|
||||
auth.setUser(user);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
await api.get("/config").then(({ data: data }) => {
|
||||
configStore.set(data);
|
||||
});
|
||||
await api.get("/config").then(({ data: data }) => {
|
||||
configStore.set(data);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
const allCookies = Cookies.get(); // Get all cookies
|
||||
for (let cookie in allCookies) {
|
||||
Cookies.remove(cookie); // Remove each cookie
|
||||
}
|
||||
router.push({
|
||||
name: "login",
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import type { WatcherDict } from "./WatcherDict";
|
||||
|
||||
export type HeartbeatResponse = {
|
||||
VERSION: string;
|
||||
SETUP_WIZARD: boolean;
|
||||
WATCHER: WatcherDict;
|
||||
SCHEDULER: SchedulerDict;
|
||||
ANY_SOURCE_ENABLED: boolean;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import CollectionListItem from "@/components/common/Collection/ListItem.vue";
|
||||
import collectionApi from "@/services/api/collection";
|
||||
import storeCollections from "@/stores/collections";
|
||||
import storeNavigation from "@/stores/navigation";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import type { Emitter } from "mitt";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { inject, onMounted } from "vue";
|
||||
import { inject } from "vue";
|
||||
import { useDisplay } from "vuetify";
|
||||
|
||||
// Props
|
||||
@@ -25,17 +24,6 @@ async function addCollection() {
|
||||
function clear() {
|
||||
searchText.value = "";
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await collectionApi
|
||||
.getCollections()
|
||||
.then(({ data: collections }) => {
|
||||
collectionsStore.set(collections);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<v-navigation-drawer
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import type { UserSchema } from "@/__generated__";
|
||||
import identityApi from "@/services/api/identity";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import storeNavigation from "@/stores/navigation";
|
||||
@@ -14,28 +15,22 @@ import { useDisplay } from "vuetify";
|
||||
const navigationStore = storeNavigation();
|
||||
const router = useRouter();
|
||||
const auth = storeAuth();
|
||||
const { user, scopes } = storeToRefs(auth);
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
const { activeSettingsDrawer } = storeToRefs(navigationStore);
|
||||
const { smAndDown } = useDisplay();
|
||||
|
||||
// Functions
|
||||
async function logout() {
|
||||
identityApi
|
||||
.logout()
|
||||
.then(({ data }) => {
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: data.msg,
|
||||
icon: "mdi-check-bold",
|
||||
color: "green",
|
||||
});
|
||||
router.push({ name: "login" });
|
||||
})
|
||||
.catch(() => {
|
||||
router.push({ name: "login" });
|
||||
})
|
||||
.finally(() => {
|
||||
auth.setUser(null);
|
||||
identityApi.logout().then(({ data }) => {
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: data.msg,
|
||||
icon: "mdi-check-bold",
|
||||
color: "green",
|
||||
});
|
||||
});
|
||||
await router.push({ name: "login" });
|
||||
auth.setUser(null);
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
@@ -50,8 +45,8 @@ async function logout() {
|
||||
<v-list-img>
|
||||
<v-img
|
||||
:src="
|
||||
auth.user?.avatar_path
|
||||
? `/assets/romm/assets/${auth.user?.avatar_path}?ts=${auth.user?.updated_at}`
|
||||
user?.avatar_path
|
||||
? `/assets/romm/assets/${user?.avatar_path}?ts=${user?.updated_at}`
|
||||
: defaultAvatarPath
|
||||
"
|
||||
cover
|
||||
@@ -59,24 +54,29 @@ async function logout() {
|
||||
</v-img>
|
||||
</v-list-img>
|
||||
<v-list-item
|
||||
:title="auth.user?.username"
|
||||
:subtitle="auth.user?.role"
|
||||
:title="user?.username"
|
||||
:subtitle="user?.role"
|
||||
class="mb-1 text-shadow text-white"
|
||||
>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
<v-list rounded="0" class="pa-0">
|
||||
<v-list-item
|
||||
@click="emitter?.emit('showEditUserDialog', auth.user as UserSchema)"
|
||||
append-icon="mdi-account"
|
||||
>Profile</v-list-item
|
||||
>
|
||||
<v-list-item :to="{ name: 'settings' }" append-icon="mdi-palette"
|
||||
>UI Settings</v-list-item
|
||||
>
|
||||
<v-list-item
|
||||
v-if="auth.scopes.includes('platforms.write')"
|
||||
v-if="scopes.includes('platforms.write')"
|
||||
append-icon="mdi-table-cog"
|
||||
:to="{ name: 'management' }"
|
||||
>Library Management
|
||||
</v-list-item>
|
||||
<v-list-item
|
||||
v-if="auth.scopes.includes('users.write')"
|
||||
v-if="scopes.includes('users.write')"
|
||||
:to="{ name: 'administration' }"
|
||||
append-icon="mdi-security"
|
||||
>Administration</v-list-item
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Composables
|
||||
import { createRouter, createWebHistory } from "vue-router";
|
||||
import storeHeartbeat from "@/stores/heartbeat";
|
||||
|
||||
const routes = [
|
||||
{
|
||||
@@ -7,6 +8,11 @@ const routes = [
|
||||
name: "login",
|
||||
component: () => import("@/views/Login.vue"),
|
||||
},
|
||||
{
|
||||
path: "/setup",
|
||||
name: "setup",
|
||||
component: () => import("@/views/Setup.vue"),
|
||||
},
|
||||
{
|
||||
path: "/",
|
||||
name: "home",
|
||||
@@ -71,10 +77,17 @@ const router = createRouter({
|
||||
routes,
|
||||
});
|
||||
|
||||
router.afterEach(() => {
|
||||
// Scroll to top to avoid annoying behaviour in mobile
|
||||
window.scrollTo({ top: 0, left: 0 });
|
||||
router.beforeEach((to) => {
|
||||
const heartbeat = storeHeartbeat();
|
||||
if (to.name == "setup" && !heartbeat.value.SETUP_WIZARD) {
|
||||
router.push({ name: "dashboard" });
|
||||
}
|
||||
// TODO: check permission for views. Ex: view user can access to /scan view
|
||||
});
|
||||
|
||||
router.afterEach(() => {
|
||||
// Scroll to top to avoid annoying behaviour in mobile
|
||||
window.scrollTo({ top: 0, left: 0 });
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import router from "@/plugins/router";
|
||||
import axios from "axios";
|
||||
import cookie from "js-cookie";
|
||||
import router from "@/plugins/router";
|
||||
import Cookies from "js-cookie";
|
||||
import { debounce } from "lodash";
|
||||
|
||||
const api = axios.create({ baseURL: "/api", timeout: 120000 });
|
||||
@@ -37,9 +38,12 @@ api.interceptors.response.use(
|
||||
},
|
||||
(error) => {
|
||||
if (error.response?.status === 403) {
|
||||
const allCookies = Cookies.get(); // Get all cookies
|
||||
for (const cookie in allCookies) {
|
||||
Cookies.remove(cookie); // Remove each cookie
|
||||
}
|
||||
router.push({
|
||||
name: "login",
|
||||
params: { next: router.currentRoute.value.path },
|
||||
});
|
||||
}
|
||||
return Promise.reject(error);
|
||||
|
||||
@@ -28,21 +28,24 @@ import SettingsDrawer from "@/components/common/Navigation/SettingsDrawer.vue";
|
||||
import NewVersion from "@/components/common/NewVersion.vue";
|
||||
import DeletePlatformDialog from "@/components/common/Platform/Dialog/DeletePlatform.vue";
|
||||
import SearchCoverDialog from "@/components/common/SearchCover.vue";
|
||||
import collectionApi from "@/services/api/collection";
|
||||
import platformApi from "@/services/api/platform";
|
||||
import userApi from "@/services/api/user";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import storeCollections from "@/stores/collections";
|
||||
import storeNavigation from "@/stores/navigation";
|
||||
import storePlatforms from "@/stores/platforms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import type { Emitter } from "mitt";
|
||||
import { inject, onMounted } from "vue";
|
||||
import { inject, onBeforeMount } from "vue";
|
||||
import { useDisplay } from "vuetify";
|
||||
|
||||
// Props
|
||||
const { smAndDown } = useDisplay();
|
||||
const navigationStore = storeNavigation();
|
||||
const platformsStore = storePlatforms();
|
||||
const auth = storeAuth();
|
||||
const platformsStore = storePlatforms();
|
||||
const collectionsStore = storeCollections();
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
emitter?.on("refreshDrawer", async () => {
|
||||
const { data: platformData } = await platformApi.getPlatforms();
|
||||
@@ -50,17 +53,7 @@ emitter?.on("refreshDrawer", async () => {
|
||||
});
|
||||
|
||||
// Functions
|
||||
onMounted(async () => {
|
||||
navigationStore.resetDrawers();
|
||||
await userApi
|
||||
.fetchCurrentUser()
|
||||
.then(({ data: user }) => {
|
||||
auth.setUser(user);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
onBeforeMount(async () => {
|
||||
await platformApi
|
||||
.getPlatforms()
|
||||
.then(({ data: platforms }) => {
|
||||
@@ -69,6 +62,23 @@ onMounted(async () => {
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
await collectionApi
|
||||
.getCollections()
|
||||
.then(({ data: collections }) => {
|
||||
collectionsStore.set(collections);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
await userApi
|
||||
.fetchCurrentUser()
|
||||
.then(({ data: user }) => {
|
||||
auth.setUser(user);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
navigationStore.resetDrawers();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import identityApi from "@/services/api/identity";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import storeHeartbeat from "@/stores/heartbeat";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import type { Emitter } from "mitt";
|
||||
import { inject, onBeforeMount, ref } from "vue";
|
||||
import { inject, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
// Props
|
||||
const heartbeatStore = storeHeartbeat();
|
||||
const auth = storeAuth();
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
const router = useRouter();
|
||||
const username = ref("");
|
||||
@@ -17,13 +15,12 @@ const password = ref("");
|
||||
const visiblePassword = ref(false);
|
||||
const logging = ref(false);
|
||||
|
||||
function login() {
|
||||
async function login() {
|
||||
logging.value = true;
|
||||
identityApi
|
||||
await identityApi
|
||||
.login(username.value, password.value)
|
||||
.then(() => {
|
||||
const next = (router.currentRoute.value.query?.next || "/").toString();
|
||||
router.push(next);
|
||||
router.push({ name: "dashboard" });
|
||||
})
|
||||
.catch(({ response, message }) => {
|
||||
const errorMessage =
|
||||
@@ -51,17 +48,12 @@ function login() {
|
||||
<span id="bg" />
|
||||
|
||||
<v-container class="fill-height justify-center">
|
||||
<v-card id="card" class="py-8 px-5" width="500">
|
||||
<v-row>
|
||||
<v-card class="translucent-dark py-8 px-5" width="500">
|
||||
<v-row no-gutters>
|
||||
<v-col>
|
||||
<v-img
|
||||
src="/assets/isotipo.svg"
|
||||
class="mx-auto"
|
||||
width="200"
|
||||
height="200"
|
||||
/>
|
||||
<v-img src="/assets/isotipo.svg" class="mx-auto" width="150" />
|
||||
|
||||
<v-row class="text-white justify-center mt-2">
|
||||
<v-row class="text-white justify-center mt-2" no-gutters>
|
||||
<v-col cols="10" md="8">
|
||||
<v-form @submit.prevent>
|
||||
<v-text-field
|
||||
@@ -117,7 +109,7 @@ function login() {
|
||||
</v-row>
|
||||
</v-card>
|
||||
|
||||
<div id="version" class="position-absolute">
|
||||
<div id="version" class="text-shadow position-absolute">
|
||||
<span class="text-white">{{ heartbeatStore.value.VERSION }}</span>
|
||||
</div>
|
||||
</v-container>
|
||||
@@ -133,12 +125,7 @@ function login() {
|
||||
background: url("/assets/login_bg.png") center center;
|
||||
background-size: cover;
|
||||
}
|
||||
#card {
|
||||
background: rgba(0, 0, 0, 0.35);
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
#version {
|
||||
text-shadow: 1px 1px 1px #000000, 0 0 1px #000000;
|
||||
bottom: 0.3rem;
|
||||
right: 0.5rem;
|
||||
}
|
||||
|
||||
@@ -23,11 +23,13 @@ const metadataOptions = computed(() => [
|
||||
{
|
||||
name: "IGDB",
|
||||
value: "igdb",
|
||||
logo_path: "/assets/scrappers/igdb.png",
|
||||
disabled: !heartbeat.value.METADATA_SOURCES?.IGDB_API_ENABLED,
|
||||
},
|
||||
{
|
||||
name: "MobyGames",
|
||||
value: "moby",
|
||||
logo_path: "/assets/scrappers/moby.png",
|
||||
disabled: !heartbeat.value.METADATA_SOURCES?.MOBY_API_ENABLED,
|
||||
},
|
||||
]);
|
||||
@@ -172,11 +174,7 @@ async function stopScan() {
|
||||
>
|
||||
<template #prepend>
|
||||
<v-avatar size="25" rounded="1">
|
||||
<v-img
|
||||
:src="`/assets/scrappers/${item.raw.name
|
||||
.slice(0, 4)
|
||||
.toLowerCase()}.png`"
|
||||
/>
|
||||
<v-img :src="item.raw.logo_path" />
|
||||
</v-avatar>
|
||||
</template>
|
||||
</v-list-item>
|
||||
|
||||
228
frontend/src/views/Setup.vue
Normal file
228
frontend/src/views/Setup.vue
Normal file
@@ -0,0 +1,228 @@
|
||||
<script setup lang="ts">
|
||||
import router from "@/plugins/router";
|
||||
import userApi from "@/services/api/user";
|
||||
import storeHeartbeat from "@/stores/heartbeat";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import type { Emitter } from "mitt";
|
||||
import { useRoute } from "vue-router";
|
||||
import { computed, inject, ref } from "vue";
|
||||
import { useDisplay } from "vuetify";
|
||||
|
||||
// Props
|
||||
const { xs, smAndDown } = useDisplay();
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
const heartbeat = storeHeartbeat();
|
||||
const route = useRoute()
|
||||
const visiblePassword = ref(false);
|
||||
// Use a computed property to reactively update metadataOptions based on heartbeat
|
||||
const metadataOptions = computed(() => [
|
||||
{
|
||||
name: "IGDB",
|
||||
value: "igdb",
|
||||
logo_path: "/assets/scrappers/igdb.png",
|
||||
disabled: !heartbeat.value.METADATA_SOURCES?.IGDB_API_ENABLED,
|
||||
},
|
||||
{
|
||||
name: "MobyGames",
|
||||
value: "moby",
|
||||
logo_path: "/assets/scrappers/moby.png",
|
||||
disabled: !heartbeat.value.METADATA_SOURCES?.MOBY_API_ENABLED,
|
||||
},
|
||||
{
|
||||
name: "SteamgridDB",
|
||||
value: "sgdb",
|
||||
logo_path: "/assets/scrappers/sgdb.png",
|
||||
disabled: !heartbeat.value.STEAMGRIDDB_ENABLED,
|
||||
},
|
||||
]);
|
||||
const defaultAdminUser = ref({
|
||||
username: "",
|
||||
password: "",
|
||||
role: "admin",
|
||||
});
|
||||
const step = ref(1);
|
||||
const filledAdminUser = computed(
|
||||
() =>
|
||||
defaultAdminUser.value.username != "" &&
|
||||
defaultAdminUser.value.password != ""
|
||||
);
|
||||
const isFirstStep = computed(() => step.value == 1);
|
||||
const isLastStep = computed(() => step.value == 2);
|
||||
|
||||
// Functions
|
||||
async function finishWizard() {
|
||||
await userApi
|
||||
.createUser(defaultAdminUser.value)
|
||||
.then(() => {
|
||||
router.go(0); // Needed to get the csrftoken properly after creating default admin user
|
||||
router.push({ name: "login" });
|
||||
})
|
||||
.catch(({ response, message }) => {
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: `Unable to create user: ${
|
||||
response?.data?.detail || response?.statusText || message
|
||||
}`,
|
||||
icon: "mdi-close-circle",
|
||||
color: "red",
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span id="bg" />
|
||||
|
||||
<v-container class="fill-height justify-center">
|
||||
<v-card class="translucent-dark px-3" elevation="0">
|
||||
<v-img src="/assets/isotipo.svg" class="mx-auto mt-4" width="70" />
|
||||
<v-stepper
|
||||
:mobile="smAndDown"
|
||||
class="bg-transparent"
|
||||
:width="xs ? '' : smAndDown ? 400 : 700"
|
||||
max-width="700"
|
||||
v-model="step"
|
||||
flat
|
||||
>
|
||||
<template v-slot:default="{ prev, next }">
|
||||
<v-stepper-header>
|
||||
<v-stepper-item
|
||||
title="Create an admin user"
|
||||
:value="1"
|
||||
></v-stepper-item>
|
||||
|
||||
<v-divider></v-divider>
|
||||
|
||||
<v-stepper-item
|
||||
title="Check metadata sources"
|
||||
:value="2"
|
||||
></v-stepper-item>
|
||||
|
||||
<!-- <v-divider></v-divider> -->
|
||||
|
||||
<!-- <v-stepper-item title="Finish" :value="3"></v-stepper-item> -->
|
||||
</v-stepper-header>
|
||||
|
||||
<v-stepper-window>
|
||||
<v-stepper-window-item :value="1" :key="1">
|
||||
<v-row no-gutters>
|
||||
<v-col>
|
||||
<v-row v-if="smAndDown" no-gutters class="text-center mb-6">
|
||||
<v-col>
|
||||
<span>Create an admin user</span>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row class="text-white justify-center mt-3" no-gutters>
|
||||
<v-col cols="10" md="8">
|
||||
<v-form @submit.prevent>
|
||||
<v-text-field
|
||||
v-model="defaultAdminUser.username"
|
||||
required
|
||||
prepend-inner-icon="mdi-account"
|
||||
type="text"
|
||||
label="Username"
|
||||
variant="underlined"
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="defaultAdminUser.password"
|
||||
required
|
||||
prepend-inner-icon="mdi-lock"
|
||||
:type="visiblePassword ? 'text' : 'password'"
|
||||
label="Password"
|
||||
variant="underlined"
|
||||
:append-inner-icon="
|
||||
visiblePassword ? 'mdi-eye-off' : 'mdi-eye'
|
||||
"
|
||||
@click:append-inner="
|
||||
visiblePassword = !visiblePassword
|
||||
"
|
||||
/>
|
||||
</v-form>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-stepper-window-item>
|
||||
|
||||
<v-stepper-window-item :value="2" :key="2">
|
||||
<v-row no-gutters>
|
||||
<v-col>
|
||||
<v-row v-if="smAndDown" no-gutters class="text-center mb-6">
|
||||
<v-col>
|
||||
<span>Check metadata sources</span>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row class="justify-center align-center" no-gutters>
|
||||
<v-col id="sources">
|
||||
<v-list-item
|
||||
v-for="source in metadataOptions"
|
||||
:title="source.name"
|
||||
:subtitle="
|
||||
source.disabled ? 'API key missing or invalid' : ''
|
||||
"
|
||||
>
|
||||
<template #prepend>
|
||||
<v-avatar size="30" rounded="1">
|
||||
<v-img :src="source.logo_path" />
|
||||
</v-avatar>
|
||||
</template>
|
||||
<template #append>
|
||||
<span class="ml-2" v-if="source.disabled">❌</span>
|
||||
<span class="ml-2" v-else>✅</span>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-stepper-window-item>
|
||||
|
||||
<!-- <v-stepper-window-item :value="3" :key="3">
|
||||
<v-row class="text-center" no-gutters>
|
||||
<v-col>
|
||||
<span>Finished!</span>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-stepper-window-item> -->
|
||||
</v-stepper-window>
|
||||
|
||||
<v-stepper-actions :disabled="!filledAdminUser">
|
||||
<template #prev>
|
||||
<v-btn :ripple="false" :disabled="isFirstStep" @click="prev">{{
|
||||
isFirstStep ? "" : "previous"
|
||||
}}</v-btn>
|
||||
</template>
|
||||
<template #next>
|
||||
<v-btn @click="!isLastStep ? next() : finishWizard()">{{
|
||||
!isLastStep ? "Next" : "Finish"
|
||||
}}</v-btn>
|
||||
</template>
|
||||
</v-stepper-actions>
|
||||
</template>
|
||||
</v-stepper>
|
||||
</v-card>
|
||||
|
||||
<div id="version" class="position-absolute">
|
||||
<span class="text-white">{{ heartbeat.value.VERSION }}</span>
|
||||
</div>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
#bg {
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
background: url("/assets/login_bg.png") center center;
|
||||
background-size: cover;
|
||||
}
|
||||
#sources {
|
||||
max-width: 300px;
|
||||
}
|
||||
#version {
|
||||
text-shadow: 1px 1px 1px #000000, 0 0 1px #000000;
|
||||
bottom: 0.3rem;
|
||||
right: 0.5rem;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user