Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confirm Password #55

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
278 changes: 142 additions & 136 deletions client/app/page.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
'use client'
import React from 'react'
import Link from 'next/link'
import Router from 'next/router';
import { EyeNoneIcon, EyeOpenIcon } from '@radix-ui/react-icons'

import React from 'react';
import { useRouter } from 'next/navigation';
import { useState } from 'react';
import axios from 'axios';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import { EyeNoneIcon, EyeOpenIcon } from '@radix-ui/react-icons';

const page = () => {
const router = useRouter();
const [loginData, setloginData] = useState({
const [loginData, setLoginData] = useState({
email: '',
password: ''
})
const [newUser, setnewUser] = useState({
username:"",
email:"",
password:""
})
});
const [newUser, setNewUser] = useState({
username: "",
email: "",
password: "",
confirmPassword: "" // Added confirmPassword
});
const [loginHeight, setLoginHeight] = useState('100%');
const [signupHeight, setSignupHeight] = useState('10%');
const [showLoginForm, setShowLoginForm] = useState(true);
const [showSignupForm, setShowSignupForm] = useState(false);
const[showPassword,setshowPassword] = useState(false);
const handleeyeclick=()=>{
setshowPassword(!showPassword);
}
const [showPassword, setShowPassword] = useState(false);

const handleEyeClick = () => {
setShowPassword(!showPassword);
};

const notify = (message) => toast(message, {
position: "bottom-left",
autoClose: 5000,
Expand All @@ -38,7 +38,6 @@ const page = () => {
draggable: true,
progress: undefined,
theme: "dark",
// transition: Bounce,
});

const getCookieValue = (name) => {
Expand All @@ -64,76 +63,75 @@ const page = () => {
setSignupHeight('100%');
setShowLoginForm(false);
setShowSignupForm(true);


};

const handleSubmit = (e) => {
e.preventDefault();
loginUser(loginData);
}
e.preventDefault();
loginUser(loginData);
};

const handleChange = (e) => {
const { name, value } = e.target;
setloginData({
...loginData,
[name]: value,
});
}
const { name, value } = e.target;
setLoginData({
...loginData,
[name]: value,
});
};

const loginUser = async (credentials) => {
try {
const res = await axios.post("https://investra-26xe.vercel.app/login", credentials);
// const res = await axios.post("http://localhost:4000/login", loginData)
if (res.data.message === 'Login Successful') {
const userData = JSON.stringify(res.data)
//sessionStorage.setItem('jwt', res.data.jwt);
//sessionStorage.setItem('activeUser',userData)
document.cookie = "jwt="+res.data.jwt+"; path=/";
document.cookie = "activeUser="+userData+"; path=/";
const cookies = document.cookie.split(';').map(cookie => cookie.trim());
console.log(getCookieValue('jwt'));
router.push('/Dash');
}
} catch (error) {
notify(error.response.data)
console.log(error);
try {
const res = await axios.post("https://investra-26xe.vercel.app/login", credentials);
if (res.data.message === 'Login Successful') {
const userData = JSON.stringify(res.data);
document.cookie = "jwt=" + res.data.jwt + "; path=/";
document.cookie = "activeUser=" + userData + "; path=/";
router.push('/Dash');
}
}
} catch (error) {
notify(error.response.data);
console.log(error);
}
};

const handleSubmit2 = (e) => {
e.preventDefault();
signupUser();
}
e.preventDefault();
signupUser();
};

const handleChange2 = (e) => {
const { name, value } = e.target;
setnewUser({
setNewUser({
...newUser,
[name]: value,
});
}
const signupUser = async() => {
};

const signupUser = async () => {
if (newUser.password !== newUser.confirmPassword) {
notify("Passwords do not match");
return;
}

try {
const res = await axios.post("https://investra-26xe.vercel.app/signup", newUser);
if (res.data.message === "User added successfully") {
const userData = JSON.stringify(res.data)
document.cookie = "jwt="+res.data.jwt+"; path=/";
document.cookie = "activeUser="+userData+"; path=/";
await loginUser(userData);
}
const res = await axios.post("https://investra-26xe.vercel.app/signup", newUser);
if (res.data.message === "User added successfully") {
const userData = JSON.stringify(res.data);
document.cookie = "jwt=" + res.data.jwt + "; path=/";
document.cookie = "activeUser=" + userData + "; path=/";
await loginUser(newUser); // Update to use newUser for login
}
} catch (error) {
console.error(error);
notify("Signup failed. Please try again.");
console.error(error);
notify("Signup failed. Please try again.");
}
}
};

const showForgetPage=() =>
{
//e.preventDefault();
const showForgetPage = () => {
router.push('/Forget-Password');
}
};

return (
<>
{/* Your existing JSX */}
<ToastContainer
position="bottom-left"
autoClose={5000}
Expand All @@ -145,107 +143,115 @@ const page = () => {
draggable
pauseOnHover
theme="dark"
/>
/>
<div className="bgcontainer">
<div className="titlecard">
Investra
<br></br>
<br />
<p className='text-11xl'>
-- a place to grow --
-- a place to grow --
</p>
</div>
<div className="infocard">
<div className="logincard" style={{ height: loginHeight}} onClick={handleLoginClick}>
<div style={{opacity: showLoginForm ? 1 : 0, transition: 'all 0.5s ease'}}>
<div className="logincard" style={{ height: loginHeight }} onClick={handleLoginClick}>
<div style={{ opacity: showLoginForm ? 1 : 0, transition: 'all 0.5s ease' }}>
Login
<form className="loginform" method='post' onSubmit={handleSubmit}>
<input
className='login-text-field'
placeholder='email'
type="email"
name="email"
onChange={handleChange}
/>
<input
className='login-text-field'
placeholder='password'
type="password"
name="password"
onChange={handleChange}
/>
<span
<form className="loginform" method='post' onSubmit={handleSubmit}>
<input
className='login-text-field'
placeholder='email'
type="email"
name="email"
onChange={handleChange}
/>
<input
className='login-text-field'
placeholder='password'
type={showPassword ? 'text' : 'password'} // Toggle visibility
name="password"
onChange={handleChange}
/>
<span
className='eye-icon'
onClick={handleeyeclick}
onClick={handleEyeClick}
style={{
position: 'absolute',
right: '10px',
top: '50%',
transform: 'translateY(-50%)',
cursor: 'pointer'
}}
>
{showPassword ? <EyeNoneIcon /> : <EyeOpenIcon />}
</span>
<button
className='login-button'
type="submit">
Login
</button>
</form>
<div style={{fontSize:'20px',marginTop:'10px'}} onClick={showForgetPage}>Forget Password</div>
>
{showPassword ? <EyeOpenIcon /> : <EyeNoneIcon />}
</span>
<button
className='login-button'
type="submit">
Login
</button>
</form>
<div style={{ fontSize: '20px', marginTop: '10px', cursor: 'pointer' }} onClick={showForgetPage}>
Forget Password
</div>
</div>
</div>
<div className="logincard signupcard" style={{ height: signupHeight}} onClick={handleSignupClick}>
<div style={{opacity: showSignupForm ? 1 : 0, transition: 'all 0.5s ease',display:showSignupForm?'flex':'none'}}>
<form className="signupform" method='post' onSubmit={handleSubmit2}>
<div className="logincard signupcard" style={{ height: signupHeight }} onClick={handleSignupClick}>
<div style={{ opacity: showSignupForm ? 1 : 0, transition: 'all 0.5s ease', display: showSignupForm ? 'flex' : 'none' }}>
<form className="signupform" method='post' onSubmit={handleSubmit2}>
Signup
<input
className='signup-text-field'
placeholder='username'
type="text"
name="username"
onChange={handleChange2}
/>
<input
className='signup-text-field'
placeholder='email'
type="email"
name="email"
onChange={handleChange2}
/>
<input
className='signup-text-field'
placeholder='password'
type="password"
name="password"
onChange={handleChange2}
/>
<span
className='signup-text-field'
placeholder='username'
type="text"
name="username"
onChange={handleChange2}
/>
<input
className='signup-text-field'
placeholder='email'
type="email"
name="email"
onChange={handleChange2}
/>
<input
className='signup-text-field'
placeholder='password'
type={showPassword ? 'text' : 'password'} // Toggle visibility
name="password"
onChange={handleChange2}
/>
<span
className='eye-icon'
onClick={handleeyeclick}
onClick={handleEyeClick}
style={{
position: 'absolute',
right: '10px',
top: '50%',
transform: 'translateY(-50%)',
cursor: 'pointer'
}}
>
{showPassword ? <EyeNoneIcon /> : <EyeOpenIcon />}
</span>
<button
className='signup-button'
type="submit">
Signup
</button>
</form>
</div>
>
{showPassword ? <EyeOpenIcon /> : <EyeNoneIcon />}
</span>
<input
className='signup-text-field'
placeholder='Confirm password'
type="password"
name="confirmPassword" // Use confirmPassword
onChange={handleChange2}
/>
<button
className='signup-button'
type="submit">
Signup
</button>
</form>
</div>
</div>
</div>
</div>
</>
);
};


export default page
export default page;