Settings
diff --git a/src/routes/(user)/settings/account/+page.server.ts b/src/routes/(user)/settings/account/+page.server.ts
index 1eaf695..23277d5 100644
--- a/src/routes/(user)/settings/account/+page.server.ts
+++ b/src/routes/(user)/settings/account/+page.server.ts
@@ -1,24 +1,67 @@
+import type { PageServerLoad } from "./$types";
import { superValidate } from "sveltekit-superforms";
import { zod } from "sveltekit-superforms/adapters";
-import type { PageServerLoad } from "./$types";
-import { accountFormSchema } from "./account-form.svelte";
+import { usernameFormSchema } from "./username-form.svelte";
+import { emailRequestFormSchema, emailConfirmFormSchema } from "./email-form.svelte";
+import { passwordFormSchema } from "./password-form.svelte";
import { fail, type Actions } from "@sveltejs/kit";
export const load: PageServerLoad = async () => {
return {
- form: await superValidate(zod(accountFormSchema)),
+ usernameForm: await superValidate(zod(usernameFormSchema)),
+ emailRequestForm: await superValidate(zod(emailRequestFormSchema)),
+ emailConfirmForm: await superValidate(zod(emailConfirmFormSchema)),
+ passwordForm: await superValidate(zod(passwordFormSchema)),
};
};
export const actions: Actions = {
- default: async (event) => {
- const form = await superValidate(event, zod(accountFormSchema));
+ username: async ({ request, locals }) => {
+ const form = await superValidate(request, zod(usernameFormSchema));
if (!form.valid) {
- console.log(form);
return fail(400, {
form,
});
}
+ await locals.pocketBase.collection('users').update(locals.id, form.data);
+ return {
+ form,
+ };
+ },
+ emailRequest: async ({ request, locals }) => {
+ const form = await superValidate(request, zod(emailRequestFormSchema));
+ if (!form.valid) {
+ return fail(400, {
+ form,
+ });
+ }
+ await locals.pocketBase.collection('users').requestEmailChange(form.data.newEmail);
+ return {
+ form,
+ };
+ },
+ emailConfirm: async ({ request, locals }) => {
+ const form = await superValidate(request, zod(emailConfirmFormSchema));
+ if (!form.valid) {
+ return fail(400, {
+ form,
+ });
+ }
+ await locals.pocketBase
+ .collection('users')
+ .confirmEmailChange(form.data.token, form.data.password);
+ return {
+ form,
+ };
+ },
+ password: async ({ request, locals }) => {
+ const form = await superValidate(request, zod(passwordFormSchema));
+ if (!form.valid) {
+ return fail(400, {
+ form,
+ });
+ }
+ await locals.pocketBase.collection('users').update(locals.id, form.data);
return {
form,
};
diff --git a/src/routes/(user)/settings/account/+page.svelte b/src/routes/(user)/settings/account/+page.svelte
index db3e9b4..6918b98 100644
--- a/src/routes/(user)/settings/account/+page.svelte
+++ b/src/routes/(user)/settings/account/+page.svelte
@@ -1,7 +1,9 @@
@@ -10,9 +12,11 @@
Account
- Update your account settings. Set your preferred language and timezone.
+ Update your account settings.
-
+
+
+
diff --git a/src/routes/(user)/settings/account/account-form.svelte b/src/routes/(user)/settings/account/account-form.svelte
deleted file mode 100644
index eca3eb3..0000000
--- a/src/routes/(user)/settings/account/account-form.svelte
+++ /dev/null
@@ -1,180 +0,0 @@
-
-
-
-
-
-
- Name
-
-
-
-
-
-
- Date of Birth
-
-
-
- {dobValue ? df.format(dobValue.toDate(getLocalTimeZone())) : "Pick a date"}
-
-
- {
- const currDateObj = currDate.toDate(getLocalTimeZone());
- const today = new Date();
- today.setHours(0, 0, 0, 0);
-
- if (currDateObj > today || currDate.year < 1900) return true;
-
- return false;
- }}
- onValueChange={(value) => {
- if (value === undefined) {
- $formData.dob = undefined;
- validate("dob");
- return;
- }
- $formData.dob = value.toDate(getLocalTimeZone()).toISOString();
- validate("dob");
- }}
- />
-
-
-
-
-
-
-
-
-
-
- Language
-
- {languages.find((lang) => lang.value === $formData.language)?.label ||
- "Select a language"}
-
-
-
-
-
-
-
- No language found.
-
- {#each languages as language}
- {
- $formData.language = language.value;
- validate("language");
- }}
- >
-
- {language.label}
-
- {/each}
-
-
-
-
-
-
-
Update account
-
-
-{#if dev && PUBLIC_DEBUG_FORMS == 'true' && browser}
-
-{/if}
diff --git a/src/routes/(user)/settings/account/email-form.svelte b/src/routes/(user)/settings/account/email-form.svelte
new file mode 100644
index 0000000..caec4d5
--- /dev/null
+++ b/src/routes/(user)/settings/account/email-form.svelte
@@ -0,0 +1,134 @@
+
+
+
+
+
+
+ Request an email change
+ Receive a verification token on this email, which you can enter in the next section.
+
+
+
+
+ New email
+
+
+
Request token
+
+
+
+
+
+ {#if dev && PUBLIC_DEBUG_FORMS == 'true' && browser}
+
+
+
+ {/if}
+
+
+
+
+
+ Confirm email change
+ Enter your verification token below to confirm the email change.
+
+
+
+
+ Token
+
+
+
+
+
+
+ Password
+
+
+
+
+
+ {#if isLoading}
+
+ {/if}
+ Update password
+
+
+
+ {#if dev && PUBLIC_DEBUG_FORMS == 'true' && browser}
+
+
+
+ {/if}
+
+
diff --git a/src/routes/(user)/settings/account/password-form.svelte b/src/routes/(user)/settings/account/password-form.svelte
new file mode 100644
index 0000000..a14e412
--- /dev/null
+++ b/src/routes/(user)/settings/account/password-form.svelte
@@ -0,0 +1,92 @@
+
+
+
+
+
+
+ Change your password
+ You can change your password here.
+
+
+
+
+ Current password
+
+
+
+
+
+
+ New password
+
+
+
+
+
+
+ Confirm new password
+
+
+
+
+
+
+ {#if isLoading}
+
+ {/if}
+ Update password
+
+
+
+ {#if dev && PUBLIC_DEBUG_FORMS == 'true' && browser}
+
+
+
+ {/if}
+
+
diff --git a/src/routes/(user)/settings/account/username-form.svelte b/src/routes/(user)/settings/account/username-form.svelte
new file mode 100644
index 0000000..12ff920
--- /dev/null
+++ b/src/routes/(user)/settings/account/username-form.svelte
@@ -0,0 +1,76 @@
+
+
+
+
+
+
+ Change your username
+
+ You can modify the username used for logging in and as your handle.
+
+
+
+
+
+ Username
+
+
+
+
+
+
+ {#if isLoading}
+
+ {/if}
+ Update password
+
+
+
+ {#if dev && PUBLIC_DEBUG_FORMS == 'true' && browser}
+
+
+
+ {/if}
+
+
diff --git a/src/routes/(user)/settings/appearance/appearance-form.svelte b/src/routes/(user)/settings/appearance/appearance-form.svelte
index a369093..43f71d8 100644
--- a/src/routes/(user)/settings/appearance/appearance-form.svelte
+++ b/src/routes/(user)/settings/appearance/appearance-form.svelte
@@ -1,93 +1,104 @@
-
- Font
-
-
-
-
-
- Set the font you want to use in the dashboard.
-
-
Theme
Select the theme for the dashboard.
+
+
+