diff --git a/src/pages/Login.jsx b/src/pages/Login.jsx index 3da7ee7..e1fe578 100644 --- a/src/pages/Login.jsx +++ b/src/pages/Login.jsx @@ -34,12 +34,15 @@ function Login() { // const apiUrl = `${process.env.REACT_APP_BASE_URL}/studentLogin`; const apiUrl = `http://localhost:3000/api/v1/studentLogin`; - try { - setLoading(true); - - const response = await axios.post(apiUrl, formData); - - toast.success("Unable to login!"); + + // Assuming the response contains a token + const token = response.data.token; + + localStorage.setItem("token", token); + localStorage.setItem("canteenId", response.data.cantId); + if (formData.accountType === "User") { + toast.success("User logged in successfully!"); + navigate("/home"); } catch (error) { toast.error("Failed To Login. Please try again."); @@ -97,7 +100,10 @@ function Login() {
+ + onSubmit={submitHandler} + > +

Hello Again!

@@ -144,10 +150,14 @@ function Login() { onChange={changeHandler} /> setShowPassword((prev) => !prev)} > - {showPassword ? : } + {showPassword ? ( + + ) : ( + + )}
@@ -156,7 +166,7 @@ function Login() { className="w-full bg-gradient-to-t from-blue-950 via-blue-950 to-gray-900 py-2 rounded-2xl text-white font-semibold mb-2" disabled={loading} > - {loading ? 'Loading...' : 'Login'} + {loading ? "Loading..." : "Login"} diff --git a/src/pages/Signup.jsx b/src/pages/Signup.jsx index 22970ea..38d9ba3 100644 --- a/src/pages/Signup.jsx +++ b/src/pages/Signup.jsx @@ -10,72 +10,72 @@ import { arrows_exclamation } from "react-icons-kit/linea/arrows_exclamation"; import Loader from "../components/Loader/Loader"; function Signup() { - const [formData, setFormData] = useState({ - name: "", - email: "", - collegeName: "", - accountType: "", - password: "", - }); + const [formData, setFormData] = useState({ + name: "", + email: "", + collegeName: "", + accountType: "", + password: "", + }); - const [showPassword, setShowPassword] = useState(false); - const [lowerValidated, setLowerValidated] = useState(false); - const [upperValidated, setUpperValidated] = useState(false); - const [numberValidated, setNumberValidated] = useState(false); - const [specialValidated, setSpecialValidated] = useState(false); - const [lengthValidated, setLengthValidated] = useState(false); - const [loading, setLoading] = useState(false); + const [showPassword, setShowPassword] = useState(false); + const [lowerValidated, setLowerValidated] = useState(false); + const [upperValidated, setUpperValidated] = useState(false); + const [numberValidated, setNumberValidated] = useState(false); + const [specialValidated, setSpecialValidated] = useState(false); + const [lengthValidated, setLengthValidated] = useState(false); + const [loading, setLoading] = useState(false); - const navigate = useNavigate(); + const navigate = useNavigate(); - function PasswordChecker(event) { - const lower = new RegExp("(?=.*[a-z])"); - const upper = new RegExp("(?=.*[A-Z])"); - const number = new RegExp("(?=.*[0-9])"); - const special = new RegExp("(?=.*[!@#$%^&*])"); - const length = new RegExp("(?=.{8,})"); - const value = event.target.value; - if (lower.test(value)) { - setLowerValidated(true); - } else { - setLowerValidated(false); - } - if (upper.test(value)) { - setUpperValidated(true); - } else { - setUpperValidated(false); - } - if (number.test(value)) { - setNumberValidated(true); - } else { - setNumberValidated(false); - } - if (special.test(value)) { - setSpecialValidated(true); - } else { - setSpecialValidated(false); - } - if (length.test(value)) { - setLengthValidated(true); - } else { - setLengthValidated(false); - } + function PasswordChecker(event) { + const lower = new RegExp("(?=.*[a-z])"); + const upper = new RegExp("(?=.*[A-Z])"); + const number = new RegExp("(?=.*[0-9])"); + const special = new RegExp("(?=.*[!@#$%^&*])"); + const length = new RegExp("(?=.{8,})"); + const value = event.target.value; + if (lower.test(value)) { + setLowerValidated(true); + } else { + setLowerValidated(false); + } + if (upper.test(value)) { + setUpperValidated(true); + } else { + setUpperValidated(false); + } + if (number.test(value)) { + setNumberValidated(true); + } else { + setNumberValidated(false); + } + if (special.test(value)) { + setSpecialValidated(true); + } else { + setSpecialValidated(false); + } + if (length.test(value)) { + setLengthValidated(true); + } else { + setLengthValidated(false); + } - setFormData(prevData => ({ - ...prevData, - [event.target.name]: event.target.value, - })); - } + setFormData((prevData) => ({ + ...prevData, + [event.target.name]: event.target.value, + })); + } - function changeHandler(event) { - setFormData(prevData => ({ - ...prevData, - [event.target.name]: event.target.value, - })); - } + function changeHandler(event) { + setFormData((prevData) => ({ + ...prevData, + [event.target.name]: event.target.value, + })); + } - async function submitHandler(event) { - event.preventDefault(); + async function submitHandler(event) { + event.preventDefault(); if ( lowerValidated && @@ -85,296 +85,298 @@ function Signup() { lengthValidated ) { if (formData.accountType === "User") { - // const apiUrl = `${process.env.REACT_APP_BASE_URL}/studentSignup`; - const apiUrl = `http://localhost:3000/api/v1/studentSignup`; - try { + + // const apiUrl = `http://localhost:8000/api/v1/studentSignup`; + const apiUrl = `http://localhost:8000/api/v1/studentSignup`; + try { setLoading(true); - + const response = await axios.post(apiUrl, formData); - - toast.success("Account Created Successfully!"); + + toast.success("Account Created Successfully!"); navigate("/home"); } catch (error) { - toast.error("Failed To Create Account. Please try again."); - console.error(error); + toast.error("Failed To Create Account. Please try again."); + console.error(error); } finally { setLoading(false); } } else { - const apiUrl = `http://localhost:3000/api/v1/canteenSignup` - // const apiUrl = `${process.env.REACT_APP_BASE_URL}/canteenSignup`; + const apiUrl = `http://localhost:8000/api/v1/canteenSignup`; + // const apiUrl = `http://localhost:8000/api/v1/canteenSignup`; try { setLoading(true); - + const response = await axios.post(apiUrl, formData); - - toast.success("Account Created Successfully!"); - navigate("/home"); + const token = response.data.token; + + localStorage.setItem("token", token); + localStorage.setItem("canteenId", response.data.cantId); + toast.success("Account Created Successfully!"); + navigate(`/section/${response.data.cantId}`); } catch (error) { - toast.error("Failed To Create Account. Please try again."); - console.error(error); + toast.error("Failed To Create Account. Please try again."); + console.error(error); } finally { setLoading(false); } - } } else { - toast.error( - "Password must pass all the criteria" - ); + toast.error("Password must pass all the criteria"); + } } - return ( - <> - {loading ? ( - - ) : ( - <> -
-
-
- logo -

- Connecting You to Your College Canteens -

-
+ return ( + <> + {loading ? ( + + ) : ( + <> +
+
+
+ logo +

+ Connecting You to Your College Canteens +

+
-
-
-
-
-
+
+
+
+
+
-
- -

- Hello There! -

-

- Create an Account -

+
+ +

+ Hello There! +

+

+ Create an Account +

-
- -
+
+ +
-
- -
+
+ +
-
- -
+
+ +
-
- -
+
+ +
-
- - setShowPassword(prev => !prev)} - > - {showPassword ? ( - - ) : ( - - )} - -
+
+ + setShowPassword((prev) => !prev)} + > + {showPassword ? ( + + ) : ( + + )} + +
- + - - - Already have an account? Login - - + + + Already have an account? Login + + - {/* + {/* Validation Checks for password */} -
-
- {lowerValidated ? ( - - - - ) : ( - - - - )} - At least one lowercase letter -
-
- {upperValidated ? ( - - - - ) : ( - - - - )} - At least one uppercase letter -
-
- {numberValidated ? ( - - - - ) : ( - - - - )} - At least one number -
-
- {specialValidated ? ( - - - - ) : ( - - - - )} - At least one special character -
-
- {lengthValidated ? ( - - - - ) : ( - - - - )} - At least 8 characters -
-
- -
- -
- {/* Resolvedd the bug here */} - - )} - - ); + .list-icon.green { + color: #006400; + } + `} + +
+ {/* Resolvedd the bug here */} + + )} + + ); } export default Signup;