From fd489b055c450cf55fc155d38823122c992b85a2 Mon Sep 17 00:00:00 2001 From: Eclypsed Date: Mon, 22 Jan 2024 14:27:09 -0500 Subject: [PATCH] Fixed submit function, working on matchin passwords alert --- src/routes/+layout.svelte | 3 +-- src/routes/login/+page.svelte | 36 ++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 9e56cb7..074fabd 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -10,14 +10,13 @@ -
+
{#key $backgroundImage} {/key}
-
diff --git a/src/routes/login/+page.svelte b/src/routes/login/+page.svelte index a0fa8bf..61db7d3 100644 --- a/src/routes/login/+page.svelte +++ b/src/routes/login/+page.svelte @@ -6,40 +6,46 @@ import type { PageServerData } from "../$types"; import type { SubmitFunction } from "@sveltejs/kit"; - export let data: PageServerData + // export let data: PageServerData type FormMode = 'signIn' | 'newUser' let formMode: FormMode = 'signIn' + let passwordInput: string, confirmPasswordInput: string + let passwordsMatch: boolean = false + $: passwordsMatch = (passwordInput === confirmPasswordInput) + $: console.log(passwordsMatch) + const handleForm: SubmitFunction = ({ formData, cancel, action }) => { const actionType: string = action.search.substring(2) if (actionType !== formMode) { - cancel() - return (formMode = formMode === 'signIn' ? 'newUser' : 'signIn') + formMode = formMode === 'signIn' ? 'newUser' : 'signIn' + return cancel() } const { username, password, confirmPassword } = Object.fromEntries(formData) if (!username || !password || (formMode === 'newUser' && !confirmPassword)) { - cancel() - return ($newestAlert = ['caution', 'All fields must be filled out']) + $newestAlert = ['caution', 'All fields must be filled out'] + return cancel() } if (formMode === 'newUser') { if (username.toString().length > 30) { - cancel() - return $newestAlert = ['caution', 'Username must be 30 characters or fewer'] + $newestAlert = ['caution', 'Username must be 30 characters or fewer'] + return cancel() } if (password.toString().length < 8) { - cancel() - return $newestAlert = ['caution', 'Password must be at least 8 characters'] + $newestAlert = ['caution', 'Password must be at least 8 characters'] + return cancel() } if (password !== confirmPassword) { - cancel() - return ($newestAlert = ['caution', 'Password and Confirm Password must match']) + $newestAlert = ['caution', 'Password and Confirm Password must match'] + return cancel() } } + console.log("Passed all checks") cancel() } @@ -51,23 +57,23 @@

{formMode === 'signIn' ? 'Sign In' : 'Create New User'}

{/key}
-
+
- +
- +
-
+