diff --git a/src/TableEditor.vue b/src/TableEditor.vue index d94f13b..5dcdc94 100644 --- a/src/TableEditor.vue +++ b/src/TableEditor.vue @@ -140,61 +140,61 @@ const availableVersion = ref([11, 12]) var interval: number -onMounted(() => { - interval = setInterval(() => { - readTable() - readFoundryStatus() - }, 2000) +// onMounted(() => { +// interval = setInterval(() => { +// readTable() +// readFoundryStatus() +// }, 2000) - loadSelectedTable(+route.params.id!) +// loadSelectedTable(+route.params.id!) - hostname.value = location.host -}) +// hostname.value = location.host +// }) -onUnmounted(() => { - clearInterval(interval) - clearSelectedTable() -}) +// onUnmounted(() => { +// clearInterval(interval) +// 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 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 - } - }) - } -} +// 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++ }) -async function readFoundryStatus() { - if (activeTable.value) { - foundryStatus.value = (await getFoundryStatus(activeTable.value)) || { - running: false, - active: false, - world: 'Potato', - users: 0, - } - } -} +// async function readFoundryStatus() { +// if (activeTable.value) { +// foundryStatus.value = (await getFoundryStatus(activeTable.value)) || { +// running: false, +// active: false, +// world: 'Potato', +// users: 0, +// } +// } +//} function protectedDelete() { if (activeTable.value) { diff --git a/src/UserManager.vue b/src/UserManager.vue index 8de82b4..65f5db4 100644 --- a/src/UserManager.vue +++ b/src/UserManager.vue @@ -58,20 +58,23 @@ import DataTable from 'primevue/datatable' import ConfirmDialog from 'primevue/confirmdialog' import FloatLabel from 'primevue/floatlabel' import Checkbox from 'primevue/checkbox' -import CheckboxGroup from 'primevue/checkboxgroup'; +import CheckboxGroup from 'primevue/checkboxgroup' import Password from 'primevue/password' import type { Ref } from 'vue' import type { User } from './types' +const currentUser: Ref = useUserData() const confirm = useConfirm() const users: Ref = useUserList() function newUser(form: any): void { console.log(form) const user: User = { + id: 0, username: form.values.username, - is_admin: form.values.is_admin + is_admin: form.values.is_admin, + authenticated: false } createUser(user, form.values.password) console.log(user) diff --git a/src/user.ts b/src/user.ts index e973ff5..31a114b 100644 --- a/src/user.ts +++ b/src/user.ts @@ -4,6 +4,7 @@ import type { Ref } from 'vue' import type { User } from './types' const $current_user: Ref = ref(null) +const $user_list: Ref = ref([]) function loadCurrentUser(): void { axios.get('/api/auth/user').then((resp) => { @@ -26,6 +27,8 @@ export function useUserData(): Ref { export function login(username: string, password: string): void { axios.post('/api/auth/login', { username, password }).then((resp) => { $current_user.value = resp.data + }).then(() => { + loadCurrentUserList() }) } @@ -33,6 +36,8 @@ export function logout(): void { if ($current_user.value && $current_user.value.authenticated) { axios.post('/api/auth/logout').then((resp) => { $current_user.value = resp.data + }).then(() => { + loadCurrentUserList() }) } } @@ -48,7 +53,7 @@ export function resetPassword(password: string): void { } export function createUser(user: User, password: string): void { - if ($current_user.value.authenticated) { + if ($current_user.value !== null && $current_user.value.authenticated) { axios.post('/api/auth/users', { 'username': user.username, 'password': password, @@ -58,17 +63,19 @@ export function createUser(user: User, password: string): void { } export function deleteUser(userId: number): void { - if ($current_user.value.authenticated && $current_user.value.is_admin) { + if ($current_user.value !== null && $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 - }) + if ($current_user.value !== null && $current_user.value.is_admin) { + axios.get('/api/auth/users/all').then((resp) => { + $user_list.value = resp.data + }) + } else { + $user_list.value = [] + } } export function useUserList(): Ref {