Skip to content

Commit

Permalink
Profile functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyabnazari committed May 27, 2023
1 parent e023c29 commit 342e334
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 51 deletions.
11 changes: 0 additions & 11 deletions frontend/src/routes/(auth)/login/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 1 addition & 7 deletions frontend/src/routes/(auth)/password-reset/+page.server.ts
Original file line number Diff line number Diff line change
@@ -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 }) => {
Expand All @@ -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');
}
};
19 changes: 19 additions & 0 deletions frontend/src/routes/(auth)/profile/+page.server.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
112 changes: 83 additions & 29 deletions frontend/src/routes/(auth)/profile/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,38 +1,92 @@
<script lang="ts">
import { applyAction, enhance } from '$app/forms';
import { currentUser, pb } from '$lib/pocketbase';
</script>

<div class="hero bg-base-100 min-h-full">
<div class="hero-content">
<div class="card p-16 shadow-lg">
<div class="flex flex-col gap-8">
<div class="flex justify-center">
<h1 class="text-2xl font-bold">Profile</h1>
</div>
<div class="flex justify-center">
<div class="avatar">
<div class="ring-primary ring-offset-base-100 w-24 rounded-md ring-4 ring-offset-4">
<img src="/example-avatar-image.jpeg" alt="Example Avatar" />
<form
method="POST"
use:enhance={() => {
return async ({ result }) => {
pb.authStore.loadFromCookie(document.cookie);
await applyAction(result);
};
}}
>
<div class="form-control">
<div class="flex flex-col gap-4">
<div class="flex justify-center">
<h1 class="text-2xl font-bold">Profile</h1>
</div>
<div class="flex justify-center">
<div class="avatar">
<div class="ring-primary ring-offset-base-100 w-24 rounded-md ring-4 ring-offset-4">
<img src="/example-avatar-image.jpeg" alt="Example Avatar" />
</div>
</div>
</div>
<div class="flex justify-center">
{#if $currentUser}
<h2>{$currentUser?.username}</h2>
{:else}
<h2>Username</h2>
{/if}
</div>

<div class="form-control w-96">
<label for="name" class="label">
<span class="label-text">Name</span>
</label>
<input
type="name"
name="name"
placeholder="your name"
value={$currentUser?.name}
class="input input-bordered w-full"
/>
</div>
<div class="form-control">
<label for="email" class="label">
<span class="label-text">Email</span>
</label>
<div class="input-group">
<input
type="email"
placeholder="your email"
value={$currentUser?.email}
class="input input-bordered w-full"
disabled
/>
<a href="/email-change"><button class="btn btn-link">Change</button></a>
</div>
</div>
<div class="form-control">
<label for="password" class="label">
<span class="label-text">Password</span>
</label>
<div class="input-group">
<input
type="email"
placeholder="********"
class="input input-bordered w-full"
disabled
/>
<a href="/password-reset"><button class="btn btn-link">Change</button></a>
</div>
</div>
<div class="flex flex-row justify-center pt-8">
<div class="flex-auto">
<a href="/dashboard"><button class="btn btn-ghost">Cancel</button></a>
</div>
<div>
<button class="btn btn-primary">Save</button>
</div>
</div>
</div>
</div>
<div class="form-control w-96">
<label for="text" class="label">
<span class="label-text">Name</span>
</label>
<input type="text" placeholder="Type here" class="input input-bordered w-full" />
</div>
<div class="form-control w-96">
<label for="text" class="label">
<span class="label-text">Email</span>
</label>
<input type="text" placeholder="Type here" class="input input-bordered w-full" />
</div>
<div class="flex flex-row justify-center">
<div class="flex-auto">
<a href="/dashboard"><button class="btn btn-ghost">Cancel</button></a>
</div>
<div>
<a href="/dashboard"><button class="btn btn-primary">Save</button></a>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
4 changes: 0 additions & 4 deletions frontend/src/routes/(docs)/contact/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
<p class="py-6 text-justify text-base">
Thank you for your support and interest in our journey.
</p>
<p class="py-6 text-justify text-base">Best regards,</p>
<p class="py-6 text-justify text-base">
Kamyab Nazari & Mohammad Khezri <br /> Co-Founders
</p>
</div>
</div>
</div>

0 comments on commit 342e334

Please sign in to comment.