From 0272c6b076280633ec63519752b2ecdbebfad49a Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Wed, 11 Dec 2024 20:46:20 -0500 Subject: [PATCH] Refactor user admin settings and enhance email management functionality --- backend/server/adventures/admin.py | 4 +- .../src/routes/_allauth/[...path]/+server.ts | 8 +- frontend/src/routes/settings/+page.svelte | 90 +++++++++++++++---- 3 files changed, 78 insertions(+), 24 deletions(-) diff --git a/backend/server/adventures/admin.py b/backend/server/adventures/admin.py index 1a8f7a8..1beac0f 100644 --- a/backend/server/adventures/admin.py +++ b/backend/server/adventures/admin.py @@ -59,9 +59,9 @@ def number_of_visits(self, obj): class CustomUserAdmin(UserAdmin): model = CustomUser - list_display = ['username', 'email', 'is_staff', 'is_active', 'image_display'] + list_display = ['username', 'is_staff', 'is_active', 'image_display'] readonly_fields = ('uuid',) - search_fields = ('username', 'email') + search_fields = ('username',) fieldsets = UserAdmin.fieldsets + ( (None, {'fields': ('profile_pic', 'uuid', 'public_profile')}), ) diff --git a/frontend/src/routes/_allauth/[...path]/+server.ts b/frontend/src/routes/_allauth/[...path]/+server.ts index 9261320..92071cb 100644 --- a/frontend/src/routes/_allauth/[...path]/+server.ts +++ b/frontend/src/routes/_allauth/[...path]/+server.ts @@ -12,8 +12,8 @@ export async function GET(event) { /** @type {import('./$types').RequestHandler} */ export async function POST({ url, params, request, fetch, cookies }) { - const searchParam = url.search ? `${url.search}&format=json` : '?format=json'; - return handleRequest(url, params, request, fetch, cookies, searchParam, true); + const searchParam = url.search ? `${url.search}` : ''; + return handleRequest(url, params, request, fetch, cookies, searchParam, false); } export async function PATCH({ url, params, request, fetch, cookies }) { @@ -22,8 +22,8 @@ export async function PATCH({ url, params, request, fetch, cookies }) { } export async function PUT({ url, params, request, fetch, cookies }) { - const searchParam = url.search ? `${url.search}&format=json` : '?format=json'; - return handleRequest(url, params, request, fetch, cookies, searchParam, true); + const searchParam = url.search ? `${url.search}` : ''; + return handleRequest(url, params, request, fetch, cookies, searchParam, false); } export async function DELETE({ url, params, request, fetch, cookies }) { diff --git a/frontend/src/routes/settings/+page.svelte b/frontend/src/routes/settings/+page.svelte index 7b73e9b..6b55c8c 100644 --- a/frontend/src/routes/settings/+page.svelte +++ b/frontend/src/routes/settings/+page.svelte @@ -15,6 +15,8 @@ emails = data.props.emails; } + let new_email: string = ''; + onMount(async () => { if (browser) { const queryParams = new URLSearchParams($page.url.search); @@ -66,6 +68,38 @@ addToast('error', 'Error removing email'); } } + + async function verifyEmail(email: { email: any; verified?: boolean; primary?: boolean }) { + let res = await fetch('/_allauth/browser/v1/account/email/', { + method: 'PUT', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ email: email.email }) + }); + if (res.ok) { + addToast('success', 'Email sent to verify'); + } else { + addToast('error', 'Error verifying email. Try again in a few minutes.'); + } + } + + async function addEmail() { + let res = await fetch('/_allauth/browser/v1/account/email/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ email: new_email }) + }); + if (res.ok) { + addToast('success', 'Email added'); + emails = [...emails, { email: new_email, verified: false, primary: false }]; + new_email = ''; + } else { + addToast('error', 'Error adding email'); + } + }

{$t('settings.settings_page')}

@@ -177,33 +211,52 @@

{$t('settings.email_change')}

-
+ +
{#each emails as email} -

+

{email.email} - {email.verified ? '✅' : '❌'} - {email.primary ? '🔑' : ''} - + {#if email.verified} +

Verified
+ {:else} +
Not Verified
+ {/if} + {#if email.primary} +
Primary
+ {/if} + + {#if !email.verified} + + {/if}

{/each} {#if emails.length === 0}

No emails

{/if}
+
-
- -
-
- -
+
+
+
+ +
+
+ +
+
@@ -213,10 +266,11 @@

{$t('adventures.visited_region_check_desc')}

+

{$t('adventures.update_visited_regions_disclaimer')}

+ -

{$t('adventures.update_visited_regions_disclaimer')}