Compare commits
2 Commits
78d6c3d4f0
...
0b256863d6
| Author | SHA1 | Date | |
|---|---|---|---|
| 0b256863d6 | |||
| cb326ff8bf |
45
nginx/vue/src/views/admin/ManageUsers.vue
Normal file
45
nginx/vue/src/views/admin/ManageUsers.vue
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<script setup>
|
||||||
|
import Button from "@/components/input/Button.vue";
|
||||||
|
import { ref, onMounted } from "vue";
|
||||||
|
import { useAuthStore } from "@/stores/auth";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
const auth = useAuthStore();
|
||||||
|
const users = ref([]);
|
||||||
|
|
||||||
|
async function fetchUsers() {
|
||||||
|
try {
|
||||||
|
const res = await axios.get("/api/user");
|
||||||
|
users.value = res.data;
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function toggleAdmin(user) {
|
||||||
|
try {
|
||||||
|
const res = await auth.setUserAdmin(user.id, !user.admin);
|
||||||
|
user.admin = res.admin;
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(fetchUsers);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<h1>Manage Users</h1>
|
||||||
|
<div v-for="user in users" :key="user.id" class="flex flex-row items-center gap-2">
|
||||||
|
<span>{{ user.username }}</span>
|
||||||
|
<span v-if="user.admin">(admin)</span>
|
||||||
|
<Button
|
||||||
|
v-if="user.id !== auth.user.id"
|
||||||
|
@click="toggleAdmin(user)"
|
||||||
|
>
|
||||||
|
{{ user.admin ? "Demote" : "Promote" }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
Reference in New Issue
Block a user