opnform/client/pages/settings/admin.vue

84 lines
2.2 KiB
Vue
Raw Permalink Normal View History

2023-12-09 14:47:03 +00:00
<template>
<div>
<h3 class="font-semibold text-2xl text-gray-900">Admin settings</h3>
<small class="text-gray-600">Manage settings.</small>
2023-12-09 14:47:03 +00:00
<h3 class="mt-3 text-lg font-semibold mb-4">
Tools
</h3>
<div class="flex flex-wrap mb-5">
<a :href="statsUrl" target="_blank">
2023-12-09 14:47:03 +00:00
<v-button class="mx-1" color="gray" shade="lighter">
Stats
</v-button>
</a>
<a :href="horizonUrl" target="_blank">
2023-12-09 14:47:03 +00:00
<v-button class="mx-1" color="gray" shade="lighter">
Horizon
</v-button>
</a>
</div>
<h3 class="text-lg font-semibold mb-4">
Impersonate User
</h3>
<form @submit.prevent="impersonate" @keydown="form.onKeydown($event)">
<!-- Password -->
<text-input name="identifier" :form="form" label="Identifier"
:required="true" help="User Id, User Email or Form Slug"
/>
<!-- Submit Button -->
<v-button :loading="loading" class="mt-4">Impersonate User</v-button>
</form>
</div>
</template>
<script setup>
import { useRouter } from 'vue-router';
2024-01-16 10:23:16 +00:00
import {opnFetch} from "~/composables/useOpnApi.js";
import {fetchAllWorkspaces} from "~/stores/workspaces.js";
2023-12-09 14:47:03 +00:00
definePageMeta({
2024-01-19 13:27:04 +00:00
middleware: "moderator"
})
2023-12-09 14:47:03 +00:00
useOpnSeoMeta({
title: 'Admin'
})
const authStore = useAuthStore()
const workspacesStore = useWorkspacesStore()
const router = useRouter()
let form = useForm({
identifier: ''
})
2024-01-16 10:23:16 +00:00
const loading = ref(false)
2023-12-09 14:47:03 +00:00
const runtimeConfig = useRuntimeConfig()
const statsUrl = runtimeConfig.public.apiBase + '/stats'
const horizonUrl = runtimeConfig.public.apiBase + '/horizon'
const impersonate = () => {
2024-01-16 10:23:16 +00:00
loading.value = true
authStore.startImpersonating()
opnFetch('/admin/impersonate/' + encodeURI(form.identifier)).then(async (data) => {
// Save the token.
2024-01-16 10:23:16 +00:00
authStore.setToken(data.token, false)
2023-12-09 14:47:03 +00:00
// Fetch the user.
2024-01-16 10:23:16 +00:00
const userData = await opnFetch('user')
authStore.setUser(userData)
const workspaces = await fetchAllWorkspaces()
workspacesStore.set(workspaces.data.value)
loading.value = false
2023-12-09 14:47:03 +00:00
router.push({ name: 'home' })
}).catch((error) => {
2024-01-16 10:23:16 +00:00
console.error(error)
useAlert().error(error.data.message)
2024-01-16 10:23:16 +00:00
loading.value = false
})
2023-12-09 14:47:03 +00:00
}
</script>