From 342e3344316fcaf5c14df2fc19f8b4d2dbd46938 Mon Sep 17 00:00:00 2001 From: Kamyab Nazari Date: Sat, 27 May 2023 17:05:41 +0200 Subject: [PATCH] Profile functions --- .../src/routes/(auth)/login/+page.server.ts | 11 -- .../(auth)/password-reset/+page.server.ts | 8 +- .../src/routes/(auth)/profile/+page.server.ts | 19 +++ .../src/routes/(auth)/profile/+page.svelte | 112 +++++++++++++----- .../src/routes/(docs)/contact/+page.svelte | 4 - 5 files changed, 103 insertions(+), 51 deletions(-) diff --git a/frontend/src/routes/(auth)/login/+page.server.ts b/frontend/src/routes/(auth)/login/+page.server.ts index 79b2b90..fa73ca1 100644 --- a/frontend/src/routes/(auth)/login/+page.server.ts +++ b/frontend/src/routes/(auth)/login/+page.server.ts @@ -3,17 +3,6 @@ import type { Actions, PageServerLoad } from './$types'; export const actions: Actions = { default: async ({ locals, request }) => { - /* - const { formData, errors } = await validateData(await request.formData(), loginUserSchema); - - if (errors) { - return invalid(400, { - data: formData, - errors: errors.fieldErrors - }); - } - */ - const data = Object.fromEntries(await request.formData()) as { email: string; password: string; diff --git a/frontend/src/routes/(auth)/password-reset/+page.server.ts b/frontend/src/routes/(auth)/password-reset/+page.server.ts index 7905773..3a3250e 100644 --- a/frontend/src/routes/(auth)/password-reset/+page.server.ts +++ b/frontend/src/routes/(auth)/password-reset/+page.server.ts @@ -1,5 +1,5 @@ import { redirect } from '@sveltejs/kit'; -import type { Actions, PageServerLoad } from './$types'; +import type { Actions } from './$types'; export const actions: Actions = { default: async ({ locals, request }) => { @@ -17,9 +17,3 @@ export const actions: Actions = { throw redirect(303, '/login'); } }; - -export const load: PageServerLoad = async ({ locals }) => { - if (locals.user) { - throw redirect(303, '/dashboard'); - } -}; diff --git a/frontend/src/routes/(auth)/profile/+page.server.ts b/frontend/src/routes/(auth)/profile/+page.server.ts index 66def6d..b7dfe90 100644 --- a/frontend/src/routes/(auth)/profile/+page.server.ts +++ b/frontend/src/routes/(auth)/profile/+page.server.ts @@ -1,5 +1,24 @@ import { redirect } from '@sveltejs/kit'; import type { PageServerLoad } from './$types'; +import type { Actions } from './$types'; + +export const actions: Actions = { + default: async ({ locals, request }) => { + const data = Object.fromEntries(await request.formData()) as { + name: string; + email: string; + }; + + try { + await locals.pb.collection('users').update(locals.user.id, data); + } catch (err) { + console.error(err); + throw err; + } + + throw redirect(303, '/dashboard'); + } +}; export const load: PageServerLoad = async ({ locals }) => { if (!locals.user) { diff --git a/frontend/src/routes/(auth)/profile/+page.svelte b/frontend/src/routes/(auth)/profile/+page.svelte index 9b790a2..36fa264 100644 --- a/frontend/src/routes/(auth)/profile/+page.svelte +++ b/frontend/src/routes/(auth)/profile/+page.svelte @@ -1,38 +1,92 @@ + +
-
-
-

Profile

-
-
-
-
- Example Avatar +
{ + return async ({ result }) => { + pb.authStore.loadFromCookie(document.cookie); + await applyAction(result); + }; + }} + > +
+
+
+

Profile

+
+
+
+
+ Example Avatar +
+
+
+
+ {#if $currentUser} +

{$currentUser?.username}

+ {:else} +

Username

+ {/if} +
+ +
+ + +
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+ +
+
+ +
-
- - -
-
- - -
-
-
- -
-
- -
-
-
+
diff --git a/frontend/src/routes/(docs)/contact/+page.svelte b/frontend/src/routes/(docs)/contact/+page.svelte index b3df462..77cd2d0 100644 --- a/frontend/src/routes/(docs)/contact/+page.svelte +++ b/frontend/src/routes/(docs)/contact/+page.svelte @@ -32,10 +32,6 @@

Thank you for your support and interest in our journey.

-

Best regards,

-

- Kamyab Nazari & Mohammad Khezri
Co-Founders -