-
+
AgroHelp
diff --git a/FrontEnd/src/pages/common/Login.jsx b/FrontEnd/src/pages/common/Login.jsx
index 0dce1de..5436819 100644
--- a/FrontEnd/src/pages/common/Login.jsx
+++ b/FrontEnd/src/pages/common/Login.jsx
@@ -1,16 +1,23 @@
-import React from 'react';
import { useState, useEffect } from 'react';
import { Link, useNavigate, useLocation } from 'react-router-dom';
import { useGlobalContext } from '../../context/ContextProvider';
import { login } from '../../api/user';
-import { ImLeaf } from 'react-icons/im';
+import logo from '../../assets/logo.svg';
+import googleLogo from '../../assets/googleLogo.svg';
+import { IoIosEyeOff, IoIosEye } from 'react-icons/io';
const Login = () => {
+
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
+ const [showPassword, setShowPassword] = useState(false);
+
+ const togglePasswordVisibility = () => {
+ setShowPassword(!showPassword);
+ };
const { setUser } = useGlobalContext();
- const { error, user } = useGlobalContext();
+ const { user } = useGlobalContext();
const navigate = useNavigate();
const location = useLocation();
@@ -21,7 +28,30 @@ const Login = () => {
if (user) {
navigate(redirect);
}
- }, [navigate, user, redirect]);
+ const params = new URLSearchParams(location.search);
+ const token = params.get('token');
+ const username = params.get('username');
+ const email = params.get('email');
+ const firstName = params.get('firstName');
+ const lastName = params.get('lastName');
+ const profilePic = params.get('profilePic');
+
+ if (token) {
+ const userData = {
+ token,
+ username,
+ email,
+ firstName,
+ lastName,
+ profilePic,
+ };
+
+ localStorage.setItem('userInfo', JSON.stringify(userData));
+ setUser(userData);
+
+ navigate('/home');
+ }
+ }, [user, location, redirect, navigate, setUser]);
const submitHandler = async (e) => {
e.preventDefault();
@@ -30,356 +60,82 @@ const Login = () => {
const { data } = await login(email, password);
if (data) {
setUser(data);
+ localStorage.setItem('userInfo', JSON.stringify(data));
+ navigate(redirect);
}
}
};
- return (
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- AgroHelp
-
-
-
-
-
- USER LOGIN
-
-
Enter your login credentials
-
-
-
+ return (
+
+
+
+
+ Login to your account
+
+
+
+
+
+ {"Don't have an account?"}{" "}
+
+ Register
+
-
);
-};
+}
export default Login;
+
+
diff --git a/FrontEnd/src/pages/common/Register.jsx b/FrontEnd/src/pages/common/Register.jsx
index 140e548..3f1df43 100644
--- a/FrontEnd/src/pages/common/Register.jsx
+++ b/FrontEnd/src/pages/common/Register.jsx
@@ -2,21 +2,34 @@ import { useState, useEffect } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { useGlobalContext } from '../../context/ContextProvider';
import { register } from '../../api/user';
+import logo from '../../assets/logo.svg';
+import googleLogo from '../../assets/googleLogo.svg';
+import { IoIosEyeOff, IoIosEye } from 'react-icons/io';
const Register = () => {
const location = useLocation();
const navigate = useNavigate();
+
const [confirmPassword, setConfirmPassword] = useState('');
const [message, setMessage] = useState(null);
-
const [username, setUsername] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [firstName, setFirstName] = useState('');
const [lastName, setLastName] = useState('');
+ const [showPassword, setShowPassword] = useState(false);
+ const [showConfirmPassword, setShowConfirmPassword] = useState(false);
+
+ const togglePasswordVisibility = () => {
+ setShowPassword(!showPassword);
+ };
+
+ const toggleConfirmPasswordVisibility = () => {
+ setShowConfirmPassword(!showConfirmPassword);
+ };
const { setUser } = useGlobalContext();
- const { error, user } = useGlobalContext();
+ const { user } = useGlobalContext();
const redirect = location.search ? location.search.split('=')[1] : '/';
@@ -32,383 +45,199 @@ const Register = () => {
setMessage('Passwords do not match');
} else {
if (email && password) {
- const { data } = await register(
- username,
- firstName,
- lastName,
- email,
- password
- );
- if (data) {
- setUser(data);
+ try {
+ const { data } = await register(
+ username,
+ firstName,
+ lastName,
+ email,
+ password
+ );
+ if (data) {
+ setUser(data);
+ }
+ } catch (error) {
+ setMessage('Registration failed. Please try again.');
}
}
}
};
return (
- <>
-
-
-
+
+
+
+
+ Register for an account
+
+ {message &&
{message}
}
+