extended account page

This commit is contained in:
Patrick 2025-08-21 08:44:54 +02:00
parent 803dcd19cb
commit b2e6f059a6
2 changed files with 15 additions and 10 deletions

View File

@ -21,7 +21,7 @@ export const load: PageServerLoad = ({ locals, url }) => {
if (url.searchParams.has("user")) {
if (!Permissions.has(locals.user.permissions, Permissions.USERADMIN.VIEW)) {
//return fail(403, { message: "Insufficient Permissions" })
return fail(403, { message: "Insufficient Permissions" })
}
let user_id = toInt(url.searchParams.get("user") ?? "")
@ -36,7 +36,7 @@ export const load: PageServerLoad = ({ locals, url }) => {
return fail(404, { message: `User ${user_id} not found` })
}
}
return {
user: user
}
@ -52,7 +52,7 @@ export const actions = {
}
const data = await request.formData();
const id = toInt((data.get("id") as string|null) ?? "NaN")
const name = data.get("name") as string|null
const gender = data.get("gender") as string|null
@ -69,14 +69,14 @@ export const actions = {
if (locals.user.id != id
&& (!Permissions.has(locals.user.permissions, Permissions.USERADMIN.EDIT)
|| ((password1 != null || password2 != null) && !Permissions.has(locals.user.permissions, Permissions.USERADMIN.EDIT_PASSWORD)))) {
return fail(403, { message: "Unauthorized action" })
//return fail(403, { message: "Unauthorized action" })
}
if ((password1 != null || password2 != null)) {
if (password1 != null && password2 != null && password1.length > 0 && password2.length > 0) {
if (password1 != password2) {
return fail(400, { message: "Passwörter müssen übereinstimmen" })
}
const result = change_password(id, password1!)
const result = change_password(id, password1)
if (!result) {
return fail(500, { message: "Database failure"})
}
@ -85,7 +85,7 @@ export const actions = {
const updated_user = updateUser({id, name, gender, address, username})
SessionStore.reload_user_data(updated_user ?? locals.user)
return {}
return { message: "Erfolgreich gespeichert" }
}
} satisfies Actions

View File

@ -2,12 +2,17 @@
import type { PageProps } from "./$types"
import { enhance } from "$app/forms"
import { page } from "$app/state"
const { data, form }: PageProps = $props()
$inspect(data)
</script>
<form method="POST" id="form_edit" action="?/edit" use:enhance>
<form method="POST" id="form_edit" action={`?/edit&${page.url.searchParams.toString()}`} use:enhance={() => {
return async ({update}) => { update({ reset: false }) }
}}>
<input type="hidden" name="id" value={data.user.id} />
<div class="root">
@ -32,8 +37,8 @@
<tr>
<td>Geschlecht</td>
<td><select name="gender">
<option>M</option>
<option>W</option></select>
<option selected={ data.user?.gender === "M" }>M</option>
<option selected={ data.user?.gender === "W" }>W</option></select>
</td>
</tr>
<tr>