diff --git a/client/src/component/Signup.jsx b/client/src/component/Signup.jsx index 0aa28d2..96a8879 100644 --- a/client/src/component/Signup.jsx +++ b/client/src/component/Signup.jsx @@ -23,32 +23,55 @@ const Signup = ({ mode }) => { // eslint-disable-next-line const [errors, setErrors] = useState({}); const [isLoggedIn, setLoggedIn] = useState(false); + const [requirements, setRequirements] = useState({ + length: false, + uppercase: false, + lowercase: false, + number: false, + specialChar: false, + }); + + const handlePasswordChange = (e) => { + const newPassword = e.target.value; + setPassword(newPassword); + + setRequirements({ + length: newPassword.length >= 8, + uppercase: /[A-Z]/.test(newPassword), + lowercase: /[a-z]/.test(newPassword), + number: /\d/.test(newPassword), + specialChar: /[@$!%*?&]/.test(newPassword), + }); + }; const handleSubmit = async (e) => { e.preventDefault(); - // try { - // // Validation not working - // await registerValidation.validate( - // { name, email, password, cpassword }, - // { abortEarly: false } - // ); - - // setErrors({}); - // } catch (error) { - // const newErrors = {}; - // error.inner.forEach((err) => { - // newErrors[err.path] = err.message; - // }); + // Check if the password meets the requirements + if (!Object.values(requirements).every(Boolean)) { + setErrors((prevErrors) => ({ + ...prevErrors, + password: "Password does not meet the required criteria.", + })); + return; + } else { + setErrors((prevErrors) => ({ ...prevErrors, password: null })); + } - // setErrors(newErrors); - // return; - // } + // Check if password and confirm password match + if (password !== cpassword) { + setErrors((prevErrors) => ({ + ...prevErrors, + cpassword: "Passwords do not match.", + })); + return; + } else { + setErrors((prevErrors) => ({ ...prevErrors, cpassword: null })); + } + // Reset form after submission setTimeout(() => { - e.target.reset(); // Reset the form after 1 second - setName(""); - setEmail(""); + e.target.reset(); setPassword(""); setCPassword(""); }, 1000); @@ -76,20 +99,7 @@ const Signup = ({ mode }) => { }, body: JSON.stringify({ name, email, password }), }); - document.querySelector('#login-btn').addEventListener('click', (event) => { - event.preventDefault(); - - const emailInput = document.getElementById('login-email'); - const rememberMeCheckbox = document.getElementById('login-remember'); - - if (rememberMeCheckbox.checked) { - localStorage.setItem('rememberedEmail', emailInput.value); - } else { - localStorage.removeItem('rememberedEmail'); - } - - // Continue with your existing login logic... - }); + const json = await response.json(); if (json.success) { @@ -100,7 +110,13 @@ const Signup = ({ mode }) => { toast.error(json.message || "An error occurred. Please try again later."); } }; - + const handleRememberMe = (e) => { + if (e.target.checked) { + localStorage.setItem('rememberedEmail', credentials.email); + } else { + localStorage.removeItem('rememberedEmail'); + } + }; return (
Password must contain:
+