-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reward points are added for certain actions.
- Loading branch information
Showing
13 changed files
with
467 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,122 @@ | ||
import React, {useState} from 'react' | ||
import { NavLink } from 'react-router-dom'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import "./mix.css" | ||
import { useDispatch } from 'react-redux'; | ||
import { SetLoader } from '../redux/loadersSlice'; | ||
import { message } from 'antd'; | ||
import React, { useState } from "react"; | ||
import { NavLink } from "react-router-dom"; | ||
import { useNavigate } from "react-router-dom"; | ||
import "./mix.css"; | ||
import { useDispatch } from "react-redux"; | ||
import { SetLoader } from "../redux/loadersSlice"; | ||
import { message } from "antd"; | ||
|
||
const Login = () => { | ||
const [passShow, setPassShow] = useState(false); | ||
|
||
const [passShow, setPassShow] = useState(false); | ||
|
||
const [inpval, setInpval] = useState({ | ||
email:"", | ||
password:"" | ||
const [inpval, setInpval] = useState({ | ||
email: "", | ||
password: "", | ||
}); | ||
const navigate = useNavigate(); | ||
const dispatch = useDispatch(); | ||
const setVal = (e) => { | ||
const { name, value } = e.target; | ||
setInpval(() => { | ||
return { | ||
...inpval, | ||
[name]: value, | ||
}; | ||
}); | ||
const navigate = useNavigate(); | ||
const dispatch = useDispatch(); | ||
const setVal = (e) =>{ | ||
|
||
const {name, value} = e.target; | ||
setInpval(()=>{ | ||
return{ | ||
...inpval, | ||
[name]:value | ||
} | ||
}; | ||
|
||
const loginuser = async (e) => { | ||
e.preventDefault(); | ||
const { email, password } = inpval; | ||
|
||
if (email === "") { | ||
message.error("Please enter your email"); | ||
} else if (!email.includes("@gmail.com")) { | ||
message.error("Please enter a valid email"); | ||
} else if (password === "") { | ||
message.error("Enter your password"); | ||
} else if (password.length < 6) { | ||
message.error("Password must be at least 6 characters"); | ||
} else { | ||
dispatch(SetLoader(true)); | ||
try { | ||
const data = await fetch("/login", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ email, password }), | ||
}); | ||
}; | ||
|
||
|
||
const loginuser = async (e) => { | ||
e.preventDefault(); | ||
const { email, password } = inpval; | ||
|
||
if (email === "") { | ||
message.error("Please enter your email"); | ||
} else if (!email.includes("@gmail.com")) { | ||
message.error("Please enter a valid email"); | ||
} else if (password === "") { | ||
message.error("Enter your password"); | ||
} else if (password.length < 6) { | ||
message.error("Password must be at least 6 characters"); | ||
const res = await data.json(); | ||
dispatch(SetLoader(false)); | ||
console.log(res); | ||
if (res.status === 201) { | ||
localStorage.setItem("usersdatatoken", res.result.token); | ||
message.success("Welcome to CARBON CREDIT MARKETPLACE"); | ||
navigate("/home"); | ||
setInpval({ ...inpval, email: "", password: "" }); | ||
} else if (res.error === "User account is blocked") { | ||
message.error("Your account is blocked!!!"); | ||
} else { | ||
dispatch(SetLoader(true)); | ||
try { | ||
const data = await fetch("/login", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify({ email, password }) | ||
}); | ||
const res = await data.json(); | ||
dispatch(SetLoader(false)); | ||
console.log(res); | ||
if (res.status === 201) { | ||
localStorage.setItem("usersdatatoken", res.result.token); | ||
message.success("Welcome to CARBON CREDIT MARKETPLACE"); | ||
message.success("🪙 2 Credits are rewarded! 🎊") | ||
navigate("/home"); | ||
setInpval({ ...inpval, email: "", password: "" }); | ||
} else if (res.error === "User account is blocked") { | ||
message.error("Your account is blocked!!!"); | ||
} else { | ||
message.error("Invalid Details"); | ||
} | ||
} catch (error) { | ||
dispatch(SetLoader(false)); | ||
message.error("An error occurred. Please try again later."); | ||
console.error("Login error:", error); | ||
} | ||
message.error("Invalid Details"); | ||
} | ||
}; | ||
|
||
return ( | ||
} catch (error) { | ||
dispatch(SetLoader(false)); | ||
message.error("An error occurred. Please try again later."); | ||
console.error("Login error:", error); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<section> | ||
<div className='form_data'> | ||
<div className='form_heading'> | ||
<h1>Welcome Back, Log In</h1> | ||
<section> | ||
<div className="form_data"> | ||
<div className="form_heading"> | ||
<h1>Welcome Back, Log In</h1> | ||
</div> | ||
<form> | ||
<div className="form_input"> | ||
<label htmlFor="email">Email</label> | ||
<input | ||
type="email" | ||
onChange={setVal} | ||
value={inpval.email} | ||
name="email" | ||
id="email" | ||
placeholder="Enter Your Email Address" | ||
/> | ||
</div> | ||
<div className="form_input"> | ||
<label htmlFor="password">Password</label> | ||
<div className="two"> | ||
<input | ||
type={!passShow ? "password" : "text"} | ||
onChange={setVal} | ||
value={inpval.password} | ||
name="password" | ||
id="password" | ||
placeholder="Enter Your Password" | ||
/> | ||
<div | ||
className="showpass" | ||
onClick={() => setPassShow(!passShow)} | ||
> | ||
{!passShow ? "Show" : "Hide"} | ||
</div> | ||
<form> | ||
<div className='form_input'> | ||
<label htmlFor="email">Email</label> | ||
<input type="email" onChange={setVal} value={inpval.email} name="email" id="email" placeholder='Enter Your Email Address' /> | ||
</div> | ||
<div className='form_input'> | ||
<label htmlFor="password">Password</label> | ||
<div className="two"> | ||
<input type={!passShow ? "password" : "text"} onChange={setVal} value={inpval.password} name="password" id="password" placeholder='Enter Your Password' /> | ||
<div className="showpass" onClick={()=>setPassShow(!passShow)}> | ||
{!passShow ? "Show" : "Hide"} | ||
</div> | ||
</div> | ||
</div> | ||
<button className='btn' onClick={loginuser}>Login</button> | ||
<p>Don't have an Account? <NavLink to="/register">Sign Up</NavLink></p> | ||
</form> | ||
</div> | ||
</div> | ||
</section> | ||
<button className="btn" onClick={loginuser}> | ||
Login | ||
</button> | ||
<p> | ||
Don't have an Account? <NavLink to="/register">Sign Up</NavLink> | ||
</p> | ||
</form> | ||
</div> | ||
</section> | ||
</> | ||
) | ||
} | ||
); | ||
}; | ||
|
||
export default Login | ||
export default Login; |
Oops, something went wrong.