From faa37db3d1c5e73963a99f8061fb106c38baa730 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson Date: Sun, 29 May 2022 17:10:08 -0500 Subject: [PATCH] glitchy registration form, writes to db --- client/src/App.scss | 9 ++ client/src/components/User/LoginForm.tsx | 53 +++++++++++- client/src/components/User/Register.tsx | 100 ++++++++++++++++++++++- 3 files changed, 157 insertions(+), 5 deletions(-) diff --git a/client/src/App.scss b/client/src/App.scss index a275dfb..ea112d3 100644 --- a/client/src/App.scss +++ b/client/src/App.scss @@ -18,6 +18,10 @@ $darkblue-1: rgb(51, 53, 66); background-color: $midblue-1; } +.light-page { + background-color: $lightblue-1; +} + button { background-color: $midblue-1; color: white; @@ -102,4 +106,9 @@ nav { justify-content: space-around; background-color: $darkblue-1 } +} + +// Login page styles +.login { + display: flex; } \ No newline at end of file diff --git a/client/src/components/User/LoginForm.tsx b/client/src/components/User/LoginForm.tsx index 254f92a..929987e 100644 --- a/client/src/components/User/LoginForm.tsx +++ b/client/src/components/User/LoginForm.tsx @@ -1,9 +1,58 @@ +import { useState } from "react"; import Page from "../../util/Page"; function LoginForm() { + enum PassVisible { + hide = 'password', + show = 'text' + } + + const [username, setUsername] = useState(); + const [password, setPassword] = useState(); + const [showPass, setShowPass] = useState(PassVisible.hide); + return ( - -

Log in here!

+ +

Welcome back to my store!

+ +
+
+

Log in with a third party provider:

+
+ +

Have a log in? Use the form below:

+ +
+
+ + setUsername(e.target.value)} + /> +
+
+ + setPassword(e.target.value)} + /> + +
+ +

Username is: {username}

+

Password is: {password}

+
+ + +
+ +
+

New here? Click here to register!

+
) } diff --git a/client/src/components/User/Register.tsx b/client/src/components/User/Register.tsx index 01ebb22..93a89c4 100644 --- a/client/src/components/User/Register.tsx +++ b/client/src/components/User/Register.tsx @@ -1,11 +1,105 @@ +import { useEffect, useState } from "react"; +import { userInfo } from '../../types/main'; +import { registerNewUser } from "../../util/apiUtils"; import Page from "../../util/Page"; function Register() { + const [name, setName] = useState(''); + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + const [verify, setVerify] = useState(''); + const [warningText, setWarningText] = useState('initial'); + + const [userData, setUserData] = useState({email: '', name: '', password: ''}); + + const conditions = [name, email, password, verify]; + + // checks password complexity + useEffect(() => { + if (!password) return; + + switch (true) { + case (!verify): + setWarningText('Verify your password below.'); + break; + case (verify !== password): + setWarningText('Passwords do not match.'); + break; + case (verify && !verify.includes('!')): + setWarningText('Password does not meet safety criteria.'); + break; + case (verify === password): + setWarningText(''); + break; + default: + throw new Error("Password switch case is faulty"); + } + }, [password, verify]); + + // checks that all conditions for registration have been met + useEffect(() => { + let evaluating = true; + + if (!(conditions.includes('')) && warningText === '') { + evaluating = false; + } + + if (!evaluating) { + const userEntry: userInfo = { + name: name, + email: email, + password: password + } + + console.log(userEntry); + setUserData(userEntry); + + setWarningText('Conditions met!'); + } + }, [conditions, warningText, userData, name, email]); + + const handleRegistration = async () => { + userData && await registerNewUser(userData); + + setName(''); + setEmail(''); + setPassword(''); + setVerify(''); + } + return ( - -

Enter your information to register:

+ +

Thanks for your interest! Enter the info below to register:

+ +
+
+ + setName(e.target.value)}/> +
+
+ + setEmail(e.target.value)}/> +
+ +

{warningText}

+ +
+ + setPassword(e.target.value)}/> +
+
+ + setVerify(e.target.value)}/> +
+
+ +
); } -export default Register; \ No newline at end of file +export default Register;