diff --git a/backend/server/main/urls.py b/backend/server/main/urls.py index f13410d..fe098bd 100644 --- a/backend/server/main/urls.py +++ b/backend/server/main/urls.py @@ -22,8 +22,8 @@ urlpatterns = [ path('auth/change-email/', ChangeEmailView.as_view(), name='change_email'), path('auth/is-registration-disabled/', IsRegistrationDisabled.as_view(), name='is_registration_disabled'), - path('auth/users', PublicUserListView.as_view(), name='public-user-list'), - path('auth/user/', PublicUserDetailView.as_view(), name='public-user-detail'), + path('auth/users/', PublicUserListView.as_view(), name='public-user-list'), + path('auth/user//', PublicUserDetailView.as_view(), name='public-user-detail'), path('csrf/', get_csrf_token, name='get_csrf_token'), re_path(r'^$', TemplateView.as_view( diff --git a/frontend/src/lib/components/UserCard.svelte b/frontend/src/lib/components/UserCard.svelte new file mode 100644 index 0000000..988a39d --- /dev/null +++ b/frontend/src/lib/components/UserCard.svelte @@ -0,0 +1,46 @@ + + +
+
+
+ {#if user.profile_pic} +
+
+ {user.username} +
+
+ {/if} +

{user.first_name} {user.last_name}

+
+

{user.username}

+ {#if user.is_staff} +
Admin
+ {/if} + +
+ +

+ {user.date_joined ? 'Joined ' + new Date(user.date_joined).toLocaleDateString() : ''} +

+
+
+ +
+
+
diff --git a/frontend/src/routes/user/[uuid]/+page.server.ts b/frontend/src/routes/user/[uuid]/+page.server.ts new file mode 100644 index 0000000..882082f --- /dev/null +++ b/frontend/src/routes/user/[uuid]/+page.server.ts @@ -0,0 +1,29 @@ +import { redirect } from '@sveltejs/kit'; +import type { PageServerLoad } from './$types'; +const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL']; +const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000'; + +export const load = (async (event) => { + if (!event.cookies.get('auth')) { + return redirect(302, '/login'); + } + const uuid = event.params.uuid; + if (!uuid) { + return redirect(302, '/users'); + } + let res = await fetch(`${serverEndpoint}/auth/user/${uuid}/`, { + headers: { + Cookie: `${event.cookies.get('auth')}` + } + }); + if (!res.ok) { + return redirect(302, '/users'); + } else { + const data = await res.json(); + return { + props: { + user: data + } + }; + } +}) satisfies PageServerLoad; diff --git a/frontend/src/routes/user/[uuid]/+page.svelte b/frontend/src/routes/user/[uuid]/+page.svelte new file mode 100644 index 0000000..ba42503 --- /dev/null +++ b/frontend/src/routes/user/[uuid]/+page.svelte @@ -0,0 +1,12 @@ + + +

{user.first_name} {user.last_name}

+

{user.username}

+ +

{user.is_staff ? 'Admin' : 'User'}

diff --git a/frontend/src/routes/users/+page.server.ts b/frontend/src/routes/users/+page.server.ts new file mode 100644 index 0000000..4aa6573 --- /dev/null +++ b/frontend/src/routes/users/+page.server.ts @@ -0,0 +1,26 @@ +import { redirect } from '@sveltejs/kit'; +import type { PageServerLoad } from './$types'; +const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL']; +const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000'; + +export const load = (async (event) => { + if (!event.cookies.get('auth')) { + return redirect(302, '/login'); + } + + const res = await fetch(`${serverEndpoint}/auth/users/`, { + headers: { + Cookie: `${event.cookies.get('auth')}` + } + }); + if (!res.ok) { + return redirect(302, '/login'); + } else { + const data = await res.json(); + return { + props: { + users: data + } + }; + } +}) satisfies PageServerLoad; diff --git a/frontend/src/routes/users/+page.svelte b/frontend/src/routes/users/+page.svelte new file mode 100644 index 0000000..85332d2 --- /dev/null +++ b/frontend/src/routes/users/+page.svelte @@ -0,0 +1,20 @@ + + +

AdventureLog Users

+
+ {#each users as user (user.uuid)} + + {/each} +
+ +{#if users.length === 0} +

No users found.

+{/if}