-
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.
Merge pull request #58 from Etlas-SCU/auth
Auth
- Loading branch information
Showing
8 changed files
with
186 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,80 @@ | ||
import React, { useState } from "react"; | ||
import React, { useContext, useState } from "react"; | ||
import OTPInput from "react-otp-input"; | ||
import { Box, Typography } from "@mui/material"; | ||
import styles from "../Header/registe-signin/Signin/sign_reg.module.css"; | ||
import { Context } from "../Context/Context"; | ||
import { RequestOtp, emailVerify } from "../../repositories/authRepo"; | ||
import MPopUp from "../PopUp_Message/error/MPopUp"; | ||
|
||
export default function Otp(props) { | ||
const [otp, setOtp] = useState(""); | ||
const { setButtonPopup, setMassagePopup } = useContext(Context); | ||
const [popup, setPopup] = useState(null); | ||
|
||
const handleSubmit = (e) => { | ||
e.preventDefault(); | ||
var jsonBody = { | ||
otp: otp, | ||
}; | ||
emailVerify(jsonBody).then((result) => { | ||
if (!result.isError) { | ||
setButtonPopup([false, ""]); | ||
setButtonPopup([true, "Sign in"]); | ||
} else { | ||
setMassagePopup(true); | ||
setPopup(<MPopUp type="error">otp is wrong</MPopUp>); | ||
} | ||
}); | ||
}; | ||
|
||
const handleResendOtp=()=>{ | ||
var jsonBody={ | ||
email:props.email | ||
} | ||
RequestOtp(jsonBody).then((res) => { | ||
if (res.isError) { | ||
setMassagePopup(true); | ||
setPopup(<MPopUp type="error">faild send otp</MPopUp>); | ||
} else { | ||
setMassagePopup(true); | ||
setPopup(<MPopUp type="done">otp sended</MPopUp>); | ||
} | ||
}); | ||
} | ||
return ( | ||
<Box className={styles.form}> | ||
<Box> | ||
<Typography className={styles.typo}> | ||
Type the OTP you received on your e-mail. | ||
</Typography> | ||
<> | ||
{popup} | ||
<Box className={styles.form}> | ||
<Box> | ||
<Typography className={styles.typo}> | ||
Type the OTP you received on your e-mail. | ||
</Typography> | ||
</Box> | ||
<form onSubmit={handleSubmit}> | ||
<OTPInput | ||
value={otp} | ||
onChange={setOtp} | ||
numInputs={4} | ||
inputStyle={styles.otp_input} | ||
Separator={<span></span>} | ||
renderInput={(props) => <input {...props} />} | ||
/> | ||
<span | ||
style={{ | ||
color: "#55c4e0", | ||
textDecoration: "underline", | ||
fontSize: "12px", | ||
}} | ||
onClick={handleResendOtp} | ||
|
||
> | ||
Resend the mail again. | ||
</span> | ||
<Box> | ||
<button type="submit">Next</button> | ||
</Box> | ||
</form> | ||
</Box> | ||
<OTPInput | ||
value={otp} | ||
onChange={setOtp} | ||
numInputs={4} | ||
inputStyle={styles.otp_input} | ||
Separator={<span></span>} | ||
renderInput={(props) => <input {...props} />} | ||
/> | ||
<Typography | ||
style={{ | ||
color: "#55c4e0", | ||
textDecoration: "underline", | ||
fontSize: "12px", | ||
}} | ||
> | ||
Resend the mail again. | ||
</Typography> | ||
<Box> | ||
<button type="submit" onClick={props.verfiy}> | ||
Next | ||
</button> | ||
</Box> | ||
</Box> | ||
</> | ||
); | ||
} |
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