KI-AGENT: Passwort-Reset im Admin-Dashboard ergänzen
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 48s
Build and Push Docker Images / build-central-services-api (push) Successful in 22s
Build and Push Docker Images / build-central-services-admin (push) Successful in 22s
Build and Push Docker Images / build-docs (push) Successful in 21s
Build and Push Docker Images / build-frontend (push) Successful in 1m24s
Build and Push Docker Images / build-website (push) Successful in 23s
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 48s
Build and Push Docker Images / build-central-services-api (push) Successful in 22s
Build and Push Docker Images / build-central-services-admin (push) Successful in 22s
Build and Push Docker Images / build-docs (push) Successful in 21s
Build and Push Docker Images / build-frontend (push) Successful in 1m24s
Build and Push Docker Images / build-website (push) Successful in 23s
This commit is contained in:
@@ -10,6 +10,10 @@ const admin = useAdmin()
|
||||
const userId = route.params.id as string
|
||||
const loading = ref(true)
|
||||
const saving = ref(false)
|
||||
const resettingPassword = ref(false)
|
||||
const resetPasswordModalOpen = ref(false)
|
||||
const resetPasswordInput = ref("")
|
||||
const resetPasswordResult = ref("")
|
||||
|
||||
const userForm = ref<AdminUser | null>(null)
|
||||
const roles = ref<AdminRole[]>([])
|
||||
@@ -168,6 +172,64 @@ const saveUser = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const resetPassword = async () => {
|
||||
if (!userForm.value || resettingPassword.value) return
|
||||
|
||||
const password = resetPasswordInput.value.trim()
|
||||
if (password && password.length < 8) {
|
||||
toast.add({ title: "Das Passwort muss mindestens 8 Zeichen lang sein", color: "red" })
|
||||
return
|
||||
}
|
||||
|
||||
resettingPassword.value = true
|
||||
|
||||
try {
|
||||
const response = await admin.resetUserPassword(userForm.value.id, password)
|
||||
resetPasswordResult.value = response.initialPassword
|
||||
resetPasswordInput.value = ""
|
||||
userForm.value.must_change_password = true
|
||||
|
||||
toast.add({
|
||||
title: "Passwort zurückgesetzt",
|
||||
description: "Das neue Initialpasswort wird einmalig angezeigt.",
|
||||
color: "green",
|
||||
})
|
||||
} catch (err: any) {
|
||||
console.error("[administration/users/reset-password]", err)
|
||||
toast.add({
|
||||
title: "Passwort konnte nicht zurückgesetzt werden",
|
||||
description: err?.data?.error || err?.message || "Unbekannter Fehler",
|
||||
color: "red",
|
||||
})
|
||||
} finally {
|
||||
resettingPassword.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const copyResetPassword = async () => {
|
||||
if (!resetPasswordResult.value) return
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(resetPasswordResult.value)
|
||||
toast.add({ title: "Passwort kopiert", color: "green" })
|
||||
} catch (err) {
|
||||
console.error("[administration/users/copy-password]", err)
|
||||
toast.add({ title: "Passwort konnte nicht kopiert werden", color: "red" })
|
||||
}
|
||||
}
|
||||
|
||||
const openResetPasswordModal = () => {
|
||||
resetPasswordInput.value = ""
|
||||
resetPasswordResult.value = ""
|
||||
resetPasswordModalOpen.value = true
|
||||
}
|
||||
|
||||
watch(resetPasswordModalOpen, (open) => {
|
||||
if (open) return
|
||||
resetPasswordInput.value = ""
|
||||
resetPasswordResult.value = ""
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
if (!auth.user?.is_admin) {
|
||||
await router.push("/")
|
||||
@@ -186,6 +248,14 @@ onMounted(async () => {
|
||||
</UButton>
|
||||
</template>
|
||||
<template #right>
|
||||
<UButton
|
||||
color="warning"
|
||||
variant="soft"
|
||||
icon="i-heroicons-key"
|
||||
@click="openResetPasswordModal"
|
||||
>
|
||||
Passwort zurücksetzen
|
||||
</UButton>
|
||||
<UButton color="primary" :loading="saving" @click="saveUser">
|
||||
Speichern
|
||||
</UButton>
|
||||
@@ -327,4 +397,71 @@ onMounted(async () => {
|
||||
|
||||
<USkeleton v-if="loading" class="h-80" />
|
||||
</UDashboardPanelContent>
|
||||
|
||||
<UModal v-model:open="resetPasswordModalOpen">
|
||||
<template #content>
|
||||
<UCard>
|
||||
<template #header>
|
||||
<div class="text-lg font-semibold">Passwort zurücksetzen</div>
|
||||
</template>
|
||||
|
||||
<div class="space-y-4">
|
||||
<p class="text-sm text-gray-600">
|
||||
Setzt das Passwort für <strong>{{ userForm?.email }}</strong> sofort zurück.
|
||||
Beim nächsten Login muss der Benutzer ein eigenes Passwort vergeben.
|
||||
</p>
|
||||
|
||||
<UFormField label="Neues Initialpasswort">
|
||||
<UInput
|
||||
v-model="resetPasswordInput"
|
||||
type="text"
|
||||
autocomplete="off"
|
||||
placeholder="Leer lassen für automatisches Passwort"
|
||||
class="w-full"
|
||||
/>
|
||||
</UFormField>
|
||||
|
||||
<UAlert
|
||||
v-if="resetPasswordResult"
|
||||
title="Neues Initialpasswort"
|
||||
description="Dieses Passwort wird nur hier angezeigt. Bitte sicher an den Benutzer übermitteln."
|
||||
color="warning"
|
||||
variant="soft"
|
||||
>
|
||||
<template #actions>
|
||||
<div class="flex items-center gap-2">
|
||||
<code class="select-all rounded bg-gray-100 px-3 py-2 text-gray-900">
|
||||
{{ resetPasswordResult }}
|
||||
</code>
|
||||
<UButton
|
||||
icon="i-heroicons-clipboard-document"
|
||||
variant="soft"
|
||||
@click="copyResetPassword"
|
||||
>
|
||||
Kopieren
|
||||
</UButton>
|
||||
</div>
|
||||
</template>
|
||||
</UAlert>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="flex justify-end gap-3">
|
||||
<UButton variant="soft" color="gray" @click="resetPasswordModalOpen = false">
|
||||
Schließen
|
||||
</UButton>
|
||||
<UButton
|
||||
v-if="!resetPasswordResult"
|
||||
color="warning"
|
||||
icon="i-heroicons-key"
|
||||
:loading="resettingPassword"
|
||||
@click="resetPassword"
|
||||
>
|
||||
Passwort zurücksetzen
|
||||
</UButton>
|
||||
</div>
|
||||
</template>
|
||||
</UCard>
|
||||
</template>
|
||||
</UModal>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user