Adding in some user managment stuff
This commit is contained in:
1 parent
0ade9df7bc
commit
36c51dcd7d
6 files changed
+177
-8
No files matched your search
+1
-1
@@ -15,4 +15,4 @@ services:
|
|||||||
- action: rebuild
|
- action: rebuild
|
||||||
path: Dockerfile
|
path: Dockerfile
|
||||||
- action: restart
|
- action: restart
|
||||||
path: compose.yaml
|
|
||||||
@@ -130,12 +130,19 @@ const foundryStatus: Ref<FoundryStatus> = ref({
|
|||||||
users: 0,
|
users: 0,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const currentUser = ref({
|
||||||
|
username: 'None',
|
||||||
|
authenticated: 'False',
|
||||||
|
is_admin: 'False',
|
||||||
|
})
|
||||||
|
|
||||||
const availableVersion = ref([11, 12])
|
const availableVersion = ref([11, 12])
|
||||||
|
|
||||||
var interval: number
|
var interval: number
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
interval = setInterval(() => {
|
interval = setInterval(() => {
|
||||||
|
readTable()
|
||||||
readFoundryStatus()
|
readFoundryStatus()
|
||||||
}, 2000)
|
}, 2000)
|
||||||
|
|
||||||
@@ -149,6 +156,31 @@ onUnmounted(() => {
|
|||||||
clearSelectedTable()
|
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, () => {
|
watch(activeTable, () => {
|
||||||
forceReset.value++
|
forceReset.value++
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
<template>
|
||||||
|
|
||||||
|
<ConfirmDialog></ConfirmDialog>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<template #content>
|
||||||
|
<Form v-slot="$form" @submit="newUser">
|
||||||
|
<div>New User</div>
|
||||||
|
<FloatLabel>
|
||||||
|
<InputText name="username" />
|
||||||
|
<label> User Name </label>
|
||||||
|
</FloatLabel>
|
||||||
|
<FloatLabel>
|
||||||
|
<Password name="password" />
|
||||||
|
<label> Password </label>
|
||||||
|
</FloatLabel>
|
||||||
|
<CheckboxGroup name="is_admin">
|
||||||
|
<div>
|
||||||
|
<label >Is Admin</label>
|
||||||
|
<Checkbox binary />
|
||||||
|
</div>
|
||||||
|
</CheckboxGroup>
|
||||||
|
<Button type="submit" label="Add" />
|
||||||
|
</Form>
|
||||||
|
</template>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<template #content>
|
||||||
|
<DataTable class="Tables" :value="users">
|
||||||
|
<Column header="Username" field="username"></Column>
|
||||||
|
<Column header="Admin" field="is_admin"></Column>
|
||||||
|
<Column>
|
||||||
|
<template #body="slotProps">
|
||||||
|
<Button label="Change Password" />
|
||||||
|
<Button label="Delete" @click="protectedDelete(slotProps.data)"/>
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
</DataTable>
|
||||||
|
</template>
|
||||||
|
</Card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style></style>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import axios from 'axios'
|
||||||
|
import { reactive, ref, onMounted, watch, onUnmounted } from 'vue'
|
||||||
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
|
import { useConfirm } from 'primevue/useconfirm'
|
||||||
|
import { Form } from '@primevue/forms'
|
||||||
|
import { useUserData, createUser, deleteUser, useUserList, reloadList } from './user'
|
||||||
|
import InputText from 'primevue/inputtext'
|
||||||
|
import Button from 'primevue/button'
|
||||||
|
import Card from 'primevue/card'
|
||||||
|
import Column from 'primevue/column'
|
||||||
|
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 Password from 'primevue/password'
|
||||||
|
|
||||||
|
import type { Ref } from 'vue'
|
||||||
|
import type { User } from './types'
|
||||||
|
|
||||||
|
const confirm = useConfirm()
|
||||||
|
const users: Ref<readonly User[]> = useUserList()
|
||||||
|
|
||||||
|
function newUser(form: any): void {
|
||||||
|
console.log(form)
|
||||||
|
const user: User = {
|
||||||
|
username: form.values.username,
|
||||||
|
is_admin: form.values.is_admin
|
||||||
|
}
|
||||||
|
createUser(user, form.values.password)
|
||||||
|
console.log(user)
|
||||||
|
form.reset()
|
||||||
|
reloadList()
|
||||||
|
}
|
||||||
|
|
||||||
|
function protectedDelete(user: User) {
|
||||||
|
confirm.require({
|
||||||
|
header: `Delete?`,
|
||||||
|
message: "This will delete the table and all of it's data",
|
||||||
|
accept: () => {
|
||||||
|
deleteUser(user.id)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -6,6 +6,7 @@ import Router from './Router.vue'
|
|||||||
import TableManager from './TableManager.vue'
|
import TableManager from './TableManager.vue'
|
||||||
import TableEditor from './TableEditor.vue'
|
import TableEditor from './TableEditor.vue'
|
||||||
import CreateTable from './CreateTable.vue'
|
import CreateTable from './CreateTable.vue'
|
||||||
|
import UserManager from './UserManager.vue'
|
||||||
import Login from './Login.vue'
|
import Login from './Login.vue'
|
||||||
import 'primeflex/primeflex.css'
|
import 'primeflex/primeflex.css'
|
||||||
import ConfirmationService from 'primevue/confirmationservice'
|
import ConfirmationService from 'primevue/confirmationservice'
|
||||||
@@ -15,6 +16,7 @@ const routes = [
|
|||||||
{ name: 'edit', path: '/edit/:id', component: TableEditor },
|
{ name: 'edit', path: '/edit/:id', component: TableEditor },
|
||||||
{ name: 'new', path: '/new', component: CreateTable },
|
{ name: 'new', path: '/new', component: CreateTable },
|
||||||
{ name: 'login', path: '/login', component: Login },
|
{ name: 'login', path: '/login', component: Login },
|
||||||
|
{ name: 'user', path: '/users', component: UserManager },
|
||||||
]
|
]
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
|
|||||||
Vendored
+15
@@ -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
|
||||||
|
}
|
||||||
+36
-7
@@ -1,13 +1,7 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { ref, readonly, onMounted } from 'vue'
|
import { ref, readonly, onMounted } from 'vue'
|
||||||
import type { Ref } from 'vue'
|
import type { Ref } from 'vue'
|
||||||
|
import type { User } from './types'
|
||||||
export interface User {
|
|
||||||
id: number
|
|
||||||
username: string
|
|
||||||
is_admin: boolean
|
|
||||||
authenticated: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
const $current_user: Ref<User | null> = ref(null)
|
const $current_user: Ref<User | null> = ref(null)
|
||||||
|
|
||||||
@@ -52,3 +46,38 @@ export function resetPassword(password: string): void {
|
|||||||
password,
|
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<User[]> = ref([])
|
||||||
|
|
||||||
|
function loadCurrentUserList(): void {
|
||||||
|
axios.get('/api/auth/users/all').then((resp) => {
|
||||||
|
$user_list.value = resp.data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useUserList(): Ref<readonly User[]> {
|
||||||
|
onMounted(() => {
|
||||||
|
loadCurrentUserList()
|
||||||
|
})
|
||||||
|
return readonly($user_list)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function reloadList(): void {
|
||||||
|
loadCurrentUserList()
|
||||||
|
}
|
||||||
Reference in new issue
Block a user