diff --git a/client/src/Components/Auth/Login.jsx b/client/src/Components/Auth/Login.jsx index 469d7aa..e1157b0 100644 --- a/client/src/Components/Auth/Login.jsx +++ b/client/src/Components/Auth/Login.jsx @@ -1,178 +1,199 @@ -import React, { useState } from "react"; -import { useContext } from "react"; -import { Link, useNavigate } from "react-router-dom"; -import axios from "axios"; -import Cookies from "universal-cookie"; -import { AuthContext } from "./AuthContext"; -import BackToTopButton from "../BackToTopButton"; -import userImg from "../../assets/images/user.webp"; -import { toast } from "react-toastify"; -import { useRef } from 'react'; -import gsap from 'gsap'; -import { useGSAP } from '@gsap/react'; - -const Login = () => { - - - const cookies = new Cookies(); - const { login } = useContext(AuthContext); - - const navigate = useNavigate(); - const [inputValue, setInputValue] = useState({ - email: "", - password: "", - }); - const { email, password } = inputValue; - - const handleOnChange = (e) => { - const { name, value } = e.target; - setInputValue({ - ...inputValue, - [name]: value, - }); - }; - - const togglePasswordVisibility = () => { - setInputValue(prevState => ({ - ...prevState, - showPassword: !prevState.showPassword, - })); - }; - - useGSAP(()=>{ - const tl = gsap.timeline(); - tl.from('.text-login',{ - opacity: 0, - y:100, - duration: 1, - delay: 0.5, - ease: "power3.inOut", - stagger: { - amount: 0.5, - }, - }); - tl.from('.form-login',{ - opacity: 0, - y:100, - ease: "power3.inOut", - }); - }); - - const handleSubmit = async (e) => { - e.preventDefault(); - try { - const response = await axios.post( - `${import.meta.env.VITE_API_URL}/auth/login`, - { - ...inputValue, - }, - { - withCredentials: true, - } - ); - - if (response) { - console.log(response.data.token); - login(response.data.token); - - cookies.set("TOKEN", response.data.token, { - path: "/", - }); - } - console.log(cookies.get("TOKEN")); - - const { success, message } = response.data; - - if (success) { - navigate("/Home"); - } else { - alert(message.message); - console.log(message); - } - } catch (error) { - toast.error("Incorrect credentials. Check and try again or sign up."); - console.log(error); - } - }; - - return ( -
- user -
-

- Login Account -

-
-
- - -
-
- -
- -
- {inputValue.showPassword ? 👁 : 👀} -
-
-
-
- -

- New to the Platform? - - {" "} - Signup - -

-
-
-
-
- ); -}; - -export default Login; +import React, { useState } from "react"; +import { useContext } from "react"; +import { Link, useNavigate } from "react-router-dom"; +import axios from "axios"; +import Cookies from "universal-cookie"; +import { AuthContext } from "./AuthContext"; +import BackToTopButton from "../BackToTopButton"; +import userImg from "../../assets/images/login1.png"; +import { toast } from "react-toastify"; +import { useRef } from 'react'; +import gsap from 'gsap'; +import { useGSAP } from '@gsap/react'; + +const Login = () => { + const cookies = new Cookies(); + const { login } = useContext(AuthContext); + + const navigate = useNavigate(); + const [inputValue, setInputValue] = useState({ + email: "", + password: "", + }); + const { email, password } = inputValue; + + const handleOnChange = (e) => { + const { name, value } = e.target; + setInputValue({ + ...inputValue, + [name]: value, + }); + }; + + const togglePasswordVisibility = () => { + setInputValue(prevState => ({ + ...prevState, + showPassword: !prevState.showPassword, + })); + }; + + useGSAP(()=>{ + const tl = gsap.timeline(); + tl.from('.text-login',{ + opacity: 0, + y:100, + duration: 1, + delay: 0.5, + ease: "power3.inOut", + stagger: { + amount: 0.5, + }, + }); + tl.from('.form-login',{ + opacity: 0, + y:100, + ease: "power3.inOut", + }); + }); + + const handleSubmit = async (e) => { + e.preventDefault(); + try { + const response = await axios.post( + `${import.meta.env.VITE_API_URL}/auth/login`, + { + ...inputValue, + }, + { + withCredentials: true, + } + ); + + if (response) { + console.log(response.data.token); + login(response.data.token); + + cookies.set("TOKEN", response.data.token, { + path: "/", + }); + } + console.log(cookies.get("TOKEN")); + + const { success, message } = response.data; + + if (success) { + navigate("/Home"); + } else { + alert(message.message); + console.log(message); + } + } catch (error) { + toast.error("Incorrect credentials. Check and try again or sign up."); + console.log(error); + } + }; + + return ( +
+ +

+
+ +
+

+ Welcome Back !! +

+
+
+ + +
+
+ + +
+ +
+ {inputValue.showPassword ? 👁 : 👀} +
+
+ + *(Password must be 8-12 characters long and contain 1 00) + +
+
+
+ +
+
+ + {/*
*/} +

+ New to the Platform? + + {" "} + Signup + +

+
+
+ +
+
+
+ ); +}; + +export default Login; diff --git a/client/src/Components/Auth/Signup.jsx b/client/src/Components/Auth/Signup.jsx index 67eb3ac..20bab3c 100644 --- a/client/src/Components/Auth/Signup.jsx +++ b/client/src/Components/Auth/Signup.jsx @@ -1,228 +1,263 @@ -import React, { useState, useContext } from "react"; -import { Link, useNavigate } from "react-router-dom"; -import axios from "axios"; -import Cookies from "universal-cookie"; -import { AuthContext } from "./AuthContext"; -import BackToTopButton from "../BackToTopButton"; -import userImg from "../../assets/images/user.webp"; -import { toast } from "react-toastify"; -import gsap from 'gsap'; -import { useGSAP } from '@gsap/react'; - - -const Signup = () => { - const cookies = new Cookies(); - const { login } = useContext(AuthContext); - const navigate = useNavigate(); - const [inputValue, setInputValue] = useState({ - email: "", - password: "", - username: "", - }); - const { email, password, username } = inputValue; - - const [role, setRole] = useState("student"); - const togglePasswordVisibility = () => { - setInputValue(prevState => ({ - ...prevState, - showPassword: !prevState.showPassword, - })); - }; - - const handleOnChange = (e) => { - const { name, value } = e.target; - setInputValue({ - ...inputValue, - [name]: value, - }); - }; - - - - const handleSubmit = async (e) => { - e.preventDefault(); - const emailRegex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i; - const passwordRegex = /^(?=.*[A-Z])(?=.*[!@#$%^&*])(?=.{8,12})/; - - if (!emailRegex.test(email)) { - toast.error("Invalid email format"); - return; - } - - if (!passwordRegex.test(password)) { - toast.error("Invalid password"); - return; - } - - try { - const response = await axios.post( - `${import.meta.env.VITE_API_URL}/auth/signup`, - { - ...inputValue, - role: role, - }, - { - withCredentials: true, - } - ); - - if (response) { - console.log(response.data.token); - cookies.set("TOKEN", response.data.token, { - path: "/", - }); - } - console.log(cookies.get("TOKEN")); - - const { success, message } = response.data; - if (success) { - login(response.data.token); - cookies.set("TOKEN", response.data.token, { - path: "/", - }); - navigate("/Home"); - } else { - if (response.status === 409) { - toast.error("This email id already exists, please either login or use another email id"); - } else { - toast.error(message); // Display error message from server - } - } - } catch (error) { - toast.error("Signup Failed, Please try again"); - console.log(error); - } - }; - - useGSAP(()=>{ - const tl = gsap.timeline(); - tl.from('.text-signup',{ - duration: 1, - opacity: 0, - y: 100, - ease: 'power3.out' - }) - tl.from('.form-signup',{ - duration: 1, - opacity: 0, - y: 100, - ease: 'power3.out' - }) - }) - - return ( -
- user -
-

Create Account

-
-
- - -
-
- - -
-
- - - *(Password must be 8-12 characters long and contain 1 capital - letter and 1 special character.) - -
- -
- {inputValue.showPassword ? 👁 : 👀} -
-
-
-
- - -
-
- -

- Already have an account?{" "} - - Login - -

-
-
-
-
- ); -}; - +import React, { useState, useContext } from "react"; +import { Link, useNavigate } from "react-router-dom"; +import axios from "axios"; +import Cookies from "universal-cookie"; +import { AuthContext } from "./AuthContext"; +import BackToTopButton from "../BackToTopButton"; +import userImg from "../../assets/images/login1.png"; +import { toast } from "react-toastify"; +import gsap from 'gsap'; +import { useGSAP } from '@gsap/react'; + + +const Signup = () => { + const cookies = new Cookies(); + const { login } = useContext(AuthContext); + const navigate = useNavigate(); + const [inputValue, setInputValue] = useState({ + email: "", + password: "", + username: "", + }); + const { email, password, username } = inputValue; + + const [role, setRole] = useState("student"); + const togglePasswordVisibility = () => { + setInputValue(prevState => ({ + ...prevState, + showPassword: !prevState.showPassword, + })); + }; + + const handleOnChange = (e) => { + const { name, value } = e.target; + setInputValue({ + ...inputValue, + [name]: value, + }); + }; + + + + const handleSubmit = async (e) => { + e.preventDefault(); + const emailRegex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i; + const passwordRegex = /^(?=.*[A-Z])(?=.*[!@#$%^&*])(?=.{8,12})/; + + if (!emailRegex.test(email)) { + toast.error("Invalid email format"); + return; + } + + if (!passwordRegex.test(password)) { + toast.error("Invalid password"); + return; + } + + try { + const response = await axios.post( + `${import.meta.env.VITE_API_URL}/auth/signup`, + { + ...inputValue, + role: role, + }, + { + withCredentials: true, + } + ); + + if (response) { + console.log(response.data.token); + cookies.set("TOKEN", response.data.token, { + path: "/", + }); + } + console.log(cookies.get("TOKEN")); + + const { success, message } = response.data; + if (success) { + login(response.data.token); + cookies.set("TOKEN", response.data.token, { + path: "/", + }); + navigate("/Home"); + } else { + if (response.status === 409) { + toast.error("This email id already exists, please either login or use another email id"); + } else { + toast.error(message); // Display error message from server + } + } + } catch (error) { + toast.error("Signup Failed, Please try again"); + console.log(error); + } + }; + const customStyles = { + student: { + backgroundColor: 'rgb(17 24 39)', + }, + default: { + backgroundColor: 'transparent', + }, + }; + useGSAP(()=>{ + const tl = gsap.timeline(); + tl.from('.text-signup',{ + duration: 1, + opacity: 0, + y: 100, + delay: 0.5, + ease: 'power3.out', + stagger: { + amount: 0.5, + }, + }) + tl.from('.form-signup',{ + duration: 1, + opacity: 0, + y: 100, + ease: 'power3.out' + }) + }) + + return ( +
+ {/* user */} + +

+
+ +
+ {/*

Create Account

*/} +

+ Create Your Account +

+
+
+ + +
+
+ + +
+
+ + + *(Password must be 8-12 characters long and contain 1 capital + letter and 1 special character.) + +
+ +
+ {inputValue.showPassword ? 👁 : 👀} +
+
+
+
+ + +
+
+
+ + +
+
+

+ Already have an account?{" "} + + Login + +

+
+
+
+
+
+
+ ); +}; + export default Signup; \ No newline at end of file diff --git a/client/src/assets/images/login1.png b/client/src/assets/images/login1.png new file mode 100644 index 0000000..39a105d Binary files /dev/null and b/client/src/assets/images/login1.png differ