diff --git a/compose.yaml b/compose.yaml index 7317d06..0be0c74 100644 --- a/compose.yaml +++ b/compose.yaml @@ -15,4 +15,4 @@ services: - action: rebuild path: Dockerfile - action: restart - path: compose.yaml + diff --git a/src/TableEditor.vue b/src/TableEditor.vue index c7f8282..d94f13b 100644 --- a/src/TableEditor.vue +++ b/src/TableEditor.vue @@ -130,12 +130,19 @@ const foundryStatus: Ref = ref({ users: 0, }) +const currentUser = ref({ + username: 'None', + authenticated: 'False', + is_admin: 'False', +}) + const availableVersion = ref([11, 12]) var interval: number onMounted(() => { interval = setInterval(() => { + readTable() readFoundryStatus() }, 2000) @@ -149,6 +156,31 @@ onUnmounted(() => { clearSelectedTable() }) +function readTable() { + axios.get(`/api/tables/${route.params.id}`).then((resp) => { + table.table_name = resp.data.table_name + table.table_link = resp.data.table_link + table.active = resp.data.active + }) +} + +function readFoundryStatus() { + if (table.active) { + axios.get(`http://${activeTable.value.table_link}.${hostname.value}/api/status`).then((resp) => { + if (resp.status == 200) { + foundryStatus.running = resp.data.version + foundryStatus.active = resp.data.active + foundryStatus.world = resp.data.world + foundryStatus.users = resp.data.users + } else { + foundryStatus.running = false + foundryStatus.active = false + foundryStatus.world = 'Not Loaded' + foundryStatus.users = 0 + } + }) + } +} watch(activeTable, () => { forceReset.value++ }) diff --git a/src/UserManager.vue b/src/UserManager.vue new file mode 100644 index 0000000..8de82b4 --- /dev/null +++ b/src/UserManager.vue @@ -0,0 +1,91 @@ + + + + + diff --git a/src/main.ts b/src/main.ts index ba67f3e..f18f731 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,7 @@ import Router from './Router.vue' import TableManager from './TableManager.vue' import TableEditor from './TableEditor.vue' import CreateTable from './CreateTable.vue' +import UserManager from './UserManager.vue' import Login from './Login.vue' import 'primeflex/primeflex.css' import ConfirmationService from 'primevue/confirmationservice' @@ -15,6 +16,7 @@ const routes = [ { name: 'edit', path: '/edit/:id', component: TableEditor }, { name: 'new', path: '/new', component: CreateTable }, { name: 'login', path: '/login', component: Login }, + { name: 'user', path: '/users', component: UserManager }, ] const router = createRouter({ diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 0000000..8d83a8a --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,15 @@ +export interface User { + id: number + username: string + is_admin: boolean + authenticated: boolean +} + +export interface GameTable { + id: number + table_name: string + table_link: string + active: boolean + version: number + user_id: number +} diff --git a/src/user.ts b/src/user.ts index e37cfaf..e973ff5 100644 --- a/src/user.ts +++ b/src/user.ts @@ -1,13 +1,7 @@ import axios from 'axios' import { ref, readonly, onMounted } from 'vue' import type { Ref } from 'vue' - -export interface User { - id: number - username: string - is_admin: boolean - authenticated: boolean -} +import type { User } from './types' const $current_user: Ref = ref(null) @@ -52,3 +46,38 @@ export function resetPassword(password: string): void { password, }) } + +export function createUser(user: User, password: string): void { + if ($current_user.value.authenticated) { + axios.post('/api/auth/users', { + 'username': user.username, + 'password': password, + 'is_admin': user.is_admin + }) + } +} + +export function deleteUser(userId: number): void { + if ($current_user.value.authenticated && $current_user.value.is_admin) { + axios.delete(`/api/auth/user/${userId}`) + } +} + +const $user_list: Ref = ref([]) + +function loadCurrentUserList(): void { + axios.get('/api/auth/users/all').then((resp) => { + $user_list.value = resp.data + }) +} + +export function useUserList(): Ref { + onMounted(() => { + loadCurrentUserList() + }) + return readonly($user_list) +} + +export function reloadList(): void { + loadCurrentUserList() +}