From a8f6b6560fdb65074ffc07ef7114e09684645e89 Mon Sep 17 00:00:00 2001 From: ebby Date: Mon, 5 Oct 2026 07:27:50 +0200 Subject: [PATCH] user screen --- backend/src/backend/routers/users.py | 6 +-- blog/src/islands/DeleteUser.tsx | 60 ++++++++++++++++++++----- blog/src/islands/RegisterForm.tsx | 2 +- blog/src/islands/ToggleSubscription.tsx | 21 +++++---- blog/src/islands/UserAction.tsx | 5 +-- blog/src/islands/UserDetails.tsx | 8 ++-- blog/src/pages/user.astro | 10 +++-- blog/src/styles/global.css | 5 +++ 8 files changed, 84 insertions(+), 33 deletions(-) diff --git a/backend/src/backend/routers/users.py b/backend/src/backend/routers/users.py index c062614..7e42d06 100644 --- a/backend/src/backend/routers/users.py +++ b/backend/src/backend/routers/users.py @@ -59,7 +59,7 @@ def register_user(new_user: NewUser, session: Session = Depends(get_session)): except IntegrityError as e: session.rollback() - + if ("UNIQUE" in str(e)): if ("user.name" in str(e) or "user.email" in str(e)): raise HTTPException(HTTP_406_NOT_ACCEPTABLE) @@ -111,11 +111,11 @@ def change_subscription( current_user: User = Depends(get_current_user), session: Session = Depends(get_session) ): - print(subscription) - print(current_user) + current_user.subscription = subscription session.add(current_user) session.commit() + session.refresh(current_user) # TODO: diff --git a/blog/src/islands/DeleteUser.tsx b/blog/src/islands/DeleteUser.tsx index 1402740..59a27a8 100644 --- a/blog/src/islands/DeleteUser.tsx +++ b/blog/src/islands/DeleteUser.tsx @@ -1,33 +1,73 @@ -import { useState } from 'preact/hooks'; -import type { JSX } from 'preact'; -import { api, AUTH_TOKEN_KEY } from '../lib/api'; +import { useState } from "preact/hooks"; +import { api } from "../lib/api"; +import { logout } from "./Util"; +import type { JSX } from "preact/jsx-runtime"; +import { navigate } from "astro/virtual-modules/transitions-router.js"; export default function DeleteUser() { - const [loading, setLoading] = useState(false); const [error, setError] = useState(''); + const [showModal, setShowModal] = useState(false); const handleClick = async (e: JSX.TargetedEvent) => { e.preventDefault(); - setLoading(true); setError(''); + let hasError = false try { - const jwt = await api.deleteUser() + await api.deleteUser() } catch (err) { setError(err instanceof Error ? err.message : 'Löschen hat nicht geklappt'); + hasError = true } finally { - setLoading(false); - localStorage.removeItem(AUTH_TOKEN_KEY); + if (!hasError) { + logout() + navigate("/") + } } }; return (
-

Delete user

- {error &&

{error}

} + + {showModal && ( +
+
+

Nutzerkonto löschen

+

Möchtest du dein Nutzerkonto wirklich löschen?

+
+ + +
+
+
+ )}
); } diff --git a/blog/src/islands/RegisterForm.tsx b/blog/src/islands/RegisterForm.tsx index d361a01..c5d4379 100644 --- a/blog/src/islands/RegisterForm.tsx +++ b/blog/src/islands/RegisterForm.tsx @@ -43,7 +43,7 @@ export default function RegisterForm() { return (
{ e.preventDefault(); handleRegistration(); }} style="display: flex; flex-direction: column;" > -
+
{ - window.addEventListener('submit-toggle-subscription', handleSubscription); - return () => window.removeEventListener('submit-toggle-subscription', handleSubscription); - }, [subscription]); - + window.addEventListener('submit-toggle-subscription', handleSubscription); + return () => window.removeEventListener('submit-toggle-subscription', handleSubscription); + }, [subscription]); + return (
- { setSubscription(e.currentTarget.checked) }} - /> +
+ { setSubscription(e.currentTarget.checked) }} + /> + +
{error &&

{error}

}
diff --git a/blog/src/islands/UserAction.tsx b/blog/src/islands/UserAction.tsx index baf5dad..ce4fb5a 100644 --- a/blog/src/islands/UserAction.tsx +++ b/blog/src/islands/UserAction.tsx @@ -1,10 +1,10 @@ -import { useEffect, useState } from "preact/hooks" +import { useEffect } from "preact/hooks" import { checkJWTValidity, getUser } from "./Util" import React from "preact/compat"; import type { User } from "../lib/api"; export default function UserAction() { - const [user, setUser] = React.useState({ 'email': '', 'name': '', 'subscription': true }); + const [user, setUser] = React.useState(); let text = "⚓︎ Login" let link = "/login" @@ -15,7 +15,6 @@ export default function UserAction() { if (user) setUser(user) }, []) - if (user) { text = `⚓︎ ${user.name}` link = "/user" diff --git a/blog/src/islands/UserDetails.tsx b/blog/src/islands/UserDetails.tsx index 4069e8c..e9fada5 100644 --- a/blog/src/islands/UserDetails.tsx +++ b/blog/src/islands/UserDetails.tsx @@ -13,9 +13,11 @@ export default function UserDetails() { return ( -
- Nutzername: {user?.name} - E-Mail Adresse: {user?.email} +
+ Nutzername: {user?.name} + E-Mail Adresse: {user?.email}
) } \ No newline at end of file diff --git a/blog/src/pages/user.astro b/blog/src/pages/user.astro index ac5681f..cb9929a 100644 --- a/blog/src/pages/user.astro +++ b/blog/src/pages/user.astro @@ -1,4 +1,5 @@ --- +import DeleteUser from "../islands/DeleteUser"; import ToggleSubscription from "../islands/ToggleSubscription"; import UserDetails from "../islands/UserDetails"; import Form from "../layouts/Form.astro"; @@ -7,11 +8,12 @@ import Form from "../layouts/Form.astro";
- - + + + \ No newline at end of file diff --git a/blog/src/styles/global.css b/blog/src/styles/global.css index e04f36e..be08394 100644 --- a/blog/src/styles/global.css +++ b/blog/src/styles/global.css @@ -8,6 +8,7 @@ * { font-family: Arial, Helvetica, sans-serif; box-sizing: border-box; + color: var(--primary-text); } main { @@ -59,6 +60,10 @@ body { padding: 12px 12px 12px 0; } +.back-btn:hover { + color: black; +} + .submit-btn { color: white; border: none;