diff --git a/.env b/.env index 426eb40..f58ba9f 100644 --- a/.env +++ b/.env @@ -21,6 +21,10 @@ REACT_APP_SESSION_EXPIRE_MINUTES=300000 REACT_APP_SESSION_EXPIRE_CHECKER=60000 REACT_APP_LOGIN_ERROR_TIMEOUT=7000 +REACT_APP_SIGNUP_ERROR_TIMEOUT=7000 + +# Had to change the error time to 3sec cause it took too long +REACT_APP_RESET_START_ERROR_TIMEOUT=3000 #apigate.lotus.g1.wrenchboard.com:76.209.103.227 #apigate.orion.g1.wrenchboard.com:76.209.103.227 diff --git a/src/components/AuthPages/ForgotPassword/index.jsx b/src/components/AuthPages/ForgotPassword/index.jsx index d8d5f1b..589d446 100644 --- a/src/components/AuthPages/ForgotPassword/index.jsx +++ b/src/components/AuthPages/ForgotPassword/index.jsx @@ -1,49 +1,153 @@ -import React from "react"; -import { Link } from 'react-router-dom'; -import titleShape from "../../../assets/images/shape/title-shape-two.svg"; +import React, { useEffect, useState } from "react"; +import { Link, useNavigate } from 'react-router-dom'; +import WrenchBoard from "../../../assets/images/wrenchboard.png" import InputCom from "../../Helpers/Inputs/InputCom"; import AuthLayout from "../AuthLayout"; +import usersService from "../../../services/UsersService"; export default function ForgotPassword() { + const [checked, setValue] = useState(false); + const [resetLoading, setResetLoading] = useState(false) + // email + const [email, setMail] = useState(""); + const [msgError, setMsgError] = useState(''); + + const navigate = useNavigate(); + const userApi = new usersService(); + + const handleEmail = (e) => { + setMail(e?.target.value); + }; + + const humanChecker = () => { + setValue(!checked); + }; + + const resetHandler = async () => { + if (email == '') { + setMsgError('An email is required') + } else if (!checked) { + setMsgError('Check if you are human') + } + + if (email != '' && checked) { + const reqData = { email } + setResetLoading(true) + try { + const res = await userApi.StartResetPassword(reqData) + if (res.status === 200) { + const { data } = res + if (data.status == -1) { + setMsgError('This is an incorrect or duplicate email') + setResetLoading(false) + } else if (data.status > 0) { + setResetLoading(false) + navigate("/verify-you", { replace: true }) + } else{ + setMsgError("reset was not successful") + setResetLoading(false) + } + setMail("") + } + } catch (error) { + setResetLoading(false) + setMail("") + setMsgError('An error occurred') + throw new Error(error) + } finally { + setTimeout(() => { + setMsgError(null) + }, process.env.REACT_APP_RESET_START_ERROR_TIMEOUT) + } + } + setTimeout(() => { + setMsgError(null) + }, process.env.REACT_APP_RESET_START_ERROR_TIMEOUT) + } + return ( <> -
-
-
-

- Forget Password -

-
- shape +
+
+ + wrenchboard + +
+
+
+
+

+ Forget Password +

+ Enter your email to reset your password.
-
-
-
- -
-
- - Send Code - - - - - Back to Home - +
+
+ +
+ {msgError &&
{msgError}
} + {/* hCaptha clone for the time being */} +
+
+
+ {/* Checkbox */} +
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+
+
+ + +
+
diff --git a/src/components/AuthPages/Login/index.jsx b/src/components/AuthPages/Login/index.jsx index 90c6539..71f8c34 100644 --- a/src/components/AuthPages/Login/index.jsx +++ b/src/components/AuthPages/Login/index.jsx @@ -4,8 +4,6 @@ import { toast } from "react-toastify"; import googleLogo from "../../../assets/images/google-logo.svg"; import appleLogo from "../../../assets/images/apple-black.svg"; import facebookLogo from "../../../assets/images/facebook-4.svg"; -// import titleShape from "../../../assets/images/shape/title-shape.svg"; -import titleShape from "../../../assets/images/shape/login_straight_underline.svg"; import WrenchBoard from "../../../assets/images/wrenchboard.png" import usersService from "../../../services/UsersService"; import InputCom from "../../Helpers/Inputs/InputCom"; @@ -24,8 +22,6 @@ export default function Login() { setValue(!checked); }; - console.log(process.env.REACT_APP_LOGIN_ERROR_TIMEOUT) - // email const [email, setMail] = useState(""); const handleEmail = (e) => { @@ -168,7 +164,7 @@ export default function Login() { Forgot Password
*/} - {loginError &&
Invalid username or password- Please reset your password or create a new account
} + {loginError &&
Invalid username or password- Please reset your password or create a new account
} {msgError &&
{msgError}
}
diff --git a/src/components/AuthPages/SignUp/index.jsx b/src/components/AuthPages/SignUp/index.jsx index 3cd6a12..ee8732d 100644 --- a/src/components/AuthPages/SignUp/index.jsx +++ b/src/components/AuthPages/SignUp/index.jsx @@ -29,14 +29,15 @@ export default function SignUp() { // To Show and Hide Password const togglePasswordVisibility = () => { setShowPassword(!showPassword); - // return console.log('showPassword') }; + const rememberMe = () => { setValue(!checked); }; const navigate = useNavigate(); const userApi = new usersService(); + // Get Country Api const getCountryList = async () => { const res = await userApi.getSignupCountryData() @@ -74,27 +75,32 @@ export default function SignUp() { } const res = await userApi.CreateUser(reqData) + setSignUpLoading(true) + if (res.status === 200) { const { data } = res if (data.status == -1 && data.acc == 'DULPICATE') { setMsgError('This account has been already created') + setSignUpLoading(false) } if (data.status > 0 && data.internal_return == 100 && data.session != '') { localStorage.setItem("email", `${data.email}`); localStorage.setItem("country", `${data.country}`); localStorage.setItem("firstname", `${data.firstname}`); localStorage.setItem("lastname", `${data.lastname}`); - setSignUpLoading(true) setTimeout(() => { navigate("/", { replace: true }); setSignUpLoading(false) }, 2000) - console.log('Success') } else { setMsgError(data.status) + setSignUpLoading(false) } } + } else { + setMsgError('This account does not exist') + setSignUpLoading(false) } } catch (error) { throw new Error(error) @@ -102,7 +108,7 @@ export default function SignUp() { } finally { setTimeout(() => { setMsgError(null) - }, 7000) + }, process.env.REACT_APP_SIGNUP_ERROR_TIMEOUT) } } diff --git a/src/components/Helpers/Inputs/InputCom/index.jsx b/src/components/Helpers/Inputs/InputCom/index.jsx index 3e14056..5c98f9f 100644 --- a/src/components/Helpers/Inputs/InputCom/index.jsx +++ b/src/components/Helpers/Inputs/InputCom/index.jsx @@ -25,7 +25,7 @@ export default function InputCom({ {label} )} - {forgotPassword && Forgot Password?} + {forgotPassword && Forgot Password?}
{ const navigate = useNavigate(); const { pathname } = useLocation(); - //Removing Data stored at localStorage after session expires const expireSession = () => { localStorage.removeItem("email"); diff --git a/src/services/UsersService.js b/src/services/UsersService.js index cab41ac..a813893 100644 --- a/src/services/UsersService.js +++ b/src/services/UsersService.js @@ -6,6 +6,11 @@ class usersService { console.log("WRB Service Entry"); } + CreateUser(reqData){ + localStorage.setItem("session_token", ``); + return this.postAuxEnd("/createuser", reqData); + } + getHomeDate(){ var postData = { uuid: localStorage.getItem("uuid"), @@ -48,11 +53,6 @@ class usersService { return this.postAuxEnd("/apigate", null); } - CreateUser(reqData){ - localStorage.setItem("session_token", ``); - return this.postAuxEnd("/createuser", reqData); - } - getLoadProfile(){ var postData = { uuid: localStorage.getItem("uid"), @@ -221,6 +221,10 @@ class usersService { return this.postAuxEnd("/sendreferral", postData); } + StartResetPassword(reqData){ + return this.postAuxEnd("/startresetpasword", reqData) + } + getCouponRedeem(){ var postData = { uuid: localStorage.getItem("uid"),