Auto-reload user list on login/logout

This commit is contained in:
iamBadgers committed 2026-08-29 23:23:52 -07:00
1 parent 36c51dcd7d
commit 2142eec6a3
3 files changed
+65 -55

No files matched your search

+46 -46
View File
@@ -140,61 +140,61 @@ const availableVersion = ref([11, 12])
var interval: number var interval: number
onMounted(() => { // onMounted(() => {
interval = setInterval(() => { // interval = setInterval(() => {
readTable() // readTable()
readFoundryStatus() // readFoundryStatus()
}, 2000) // }, 2000)
loadSelectedTable(+route.params.id!) // loadSelectedTable(+route.params.id!)
hostname.value = location.host // hostname.value = location.host
}) // })
onUnmounted(() => { // onUnmounted(() => {
clearInterval(interval) // clearInterval(interval)
clearSelectedTable() // clearSelectedTable()
}) // })
function readTable() { // function readTable() {
axios.get(`/api/tables/${route.params.id}`).then((resp) => { // axios.get(`/api/tables/${route.params.id}`).then((resp) => {
table.table_name = resp.data.table_name // table.table_name = resp.data.table_name
table.table_link = resp.data.table_link // table.table_link = resp.data.table_link
table.active = resp.data.active // table.active = resp.data.active
}) // })
} // }
function readFoundryStatus() { // function readFoundryStatus() {
if (table.active) { // if (table.active) {
axios.get(`http://${activeTable.value.table_link}.${hostname.value}/api/status`).then((resp) => { // axios.get(`http://${activeTable.value.table_link}.${hostname.value}/api/status`).then((resp) => {
if (resp.status == 200) { // if (resp.status == 200) {
foundryStatus.running = resp.data.version // foundryStatus.running = resp.data.version
foundryStatus.active = resp.data.active // foundryStatus.active = resp.data.active
foundryStatus.world = resp.data.world // foundryStatus.world = resp.data.world
foundryStatus.users = resp.data.users // foundryStatus.users = resp.data.users
} else { // } else {
foundryStatus.running = false // foundryStatus.running = false
foundryStatus.active = false // foundryStatus.active = false
foundryStatus.world = 'Not Loaded' // foundryStatus.world = 'Not Loaded'
foundryStatus.users = 0 // foundryStatus.users = 0
} // }
}) // })
} // }
} // }
watch(activeTable, () => { watch(activeTable, () => {
forceReset.value++ forceReset.value++
}) })
async function readFoundryStatus() { // async function readFoundryStatus() {
if (activeTable.value) { // if (activeTable.value) {
foundryStatus.value = (await getFoundryStatus(activeTable.value)) || { // foundryStatus.value = (await getFoundryStatus(activeTable.value)) || {
running: false, // running: false,
active: false, // active: false,
world: 'Potato', // world: 'Potato',
users: 0, // users: 0,
} // }
} // }
} //}
function protectedDelete() { function protectedDelete() {
if (activeTable.value) { if (activeTable.value) {
+5 -2
View File
@@ -58,20 +58,23 @@ import DataTable from 'primevue/datatable'
import ConfirmDialog from 'primevue/confirmdialog' import ConfirmDialog from 'primevue/confirmdialog'
import FloatLabel from 'primevue/floatlabel' import FloatLabel from 'primevue/floatlabel'
import Checkbox from 'primevue/checkbox' import Checkbox from 'primevue/checkbox'
import CheckboxGroup from 'primevue/checkboxgroup'; import CheckboxGroup from 'primevue/checkboxgroup'
import Password from 'primevue/password' import Password from 'primevue/password'
import type { Ref } from 'vue' import type { Ref } from 'vue'
import type { User } from './types' import type { User } from './types'
const currentUser: Ref<User | null> = useUserData()
const confirm = useConfirm() const confirm = useConfirm()
const users: Ref<readonly User[]> = useUserList() const users: Ref<readonly User[]> = useUserList()
function newUser(form: any): void { function newUser(form: any): void {
console.log(form) console.log(form)
const user: User = { const user: User = {
id: 0,
username: form.values.username, username: form.values.username,
is_admin: form.values.is_admin is_admin: form.values.is_admin,
authenticated: false
} }
createUser(user, form.values.password) createUser(user, form.values.password)
console.log(user) console.log(user)
+14 -7
View File
@@ -4,6 +4,7 @@ import type { Ref } from 'vue'
import type { User } from './types' import type { User } from './types'
const $current_user: Ref<User | null> = ref(null) const $current_user: Ref<User | null> = ref(null)
const $user_list: Ref<User[]> = ref([])
function loadCurrentUser(): void { function loadCurrentUser(): void {
axios.get('/api/auth/user').then((resp) => { axios.get('/api/auth/user').then((resp) => {
@@ -26,6 +27,8 @@ export function useUserData(): Ref<User | null> {
export function login(username: string, password: string): void { export function login(username: string, password: string): void {
axios.post('/api/auth/login', { username, password }).then((resp) => { axios.post('/api/auth/login', { username, password }).then((resp) => {
$current_user.value = resp.data $current_user.value = resp.data
}).then(() => {
loadCurrentUserList()
}) })
} }
@@ -33,6 +36,8 @@ export function logout(): void {
if ($current_user.value && $current_user.value.authenticated) { if ($current_user.value && $current_user.value.authenticated) {
axios.post('/api/auth/logout').then((resp) => { axios.post('/api/auth/logout').then((resp) => {
$current_user.value = resp.data $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 { 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', { axios.post('/api/auth/users', {
'username': user.username, 'username': user.username,
'password': password, 'password': password,
@@ -58,17 +63,19 @@ export function createUser(user: User, password: string): void {
} }
export function deleteUser(userId: number): 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}`) axios.delete(`/api/auth/user/${userId}`)
} }
} }
const $user_list: Ref<User[]> = ref([])
function loadCurrentUserList(): void { function loadCurrentUserList(): void {
axios.get('/api/auth/users/all').then((resp) => { if ($current_user.value !== null && $current_user.value.is_admin) {
$user_list.value = resp.data axios.get('/api/auth/users/all').then((resp) => {
}) $user_list.value = resp.data
})
} else {
$user_list.value = []
}
} }
export function useUserList(): Ref<readonly User[]> { export function useUserList(): Ref<readonly User[]> {