Auto-reload user list on login/logout
This commit is contained in:
1 parent
36c51dcd7d
commit
2142eec6a3
3 files changed
+62
-52
No files matched your search
+46
-46
@@ -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) {
|
||||
|
||||
+5
-2
@@ -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<User | null> = useUserData()
|
||||
const confirm = useConfirm()
|
||||
const users: Ref<readonly User[]> = 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)
|
||||
|
||||
+11
-4
@@ -4,6 +4,7 @@ import type { Ref } from 'vue'
|
||||
import type { User } from './types'
|
||||
|
||||
const $current_user: Ref<User | null> = ref(null)
|
||||
const $user_list: Ref<User[]> = ref([])
|
||||
|
||||
function loadCurrentUser(): void {
|
||||
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 {
|
||||
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<User[]> = ref([])
|
||||
|
||||
function loadCurrentUserList(): void {
|
||||
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<readonly User[]> {
|
||||
|
||||
Reference in new issue
Block a user