Improved how the captcha works

This commit is contained in:
DrMint 2022-03-23 17:23:48 +01:00
parent b946974267
commit 757dab3e81
1 changed files with 6 additions and 4 deletions

View File

@ -30,8 +30,8 @@ export default function AboutUs(props: ContactProps): JSX.Element {
"stale" "stale"
); );
const random1 = randomInt(0, 10); const [randomNumber1, setRandomNumber1] = useState(randomInt(0, 10));
const random2 = randomInt(0, 10); const [randomNumber2, setRandomNumber2] = useState(randomInt(0, 10));
const subPanel = ( const subPanel = (
<SubPanel> <SubPanel>
@ -91,7 +91,7 @@ export default function AboutUs(props: ContactProps): JSX.Element {
setFormState("ongoing"); setFormState("ongoing");
if ( if (
parseInt(fields.verif.value) == random1 + random2 && parseInt(fields.verif.value) == randomNumber1 + randomNumber2 &&
formState !== "completed" formState !== "completed"
) { ) {
const content: RequestMailProps = { const content: RequestMailProps = {
@ -130,6 +130,8 @@ export default function AboutUs(props: ContactProps): JSX.Element {
} else { } else {
setFormResponse(langui.response_invalid_code); setFormResponse(langui.response_invalid_code);
setFormState("stale"); setFormState("stale");
setRandomNumber1(randomInt(0, 10));
setRandomNumber2(randomInt(0, 10));
} }
router.replace("#send-response"); router.replace("#send-response");
@ -180,7 +182,7 @@ export default function AboutUs(props: ContactProps): JSX.Element {
<label <label
className="flex-shrink-0" className="flex-shrink-0"
htmlFor="verif" htmlFor="verif"
>{`${random1} + ${random2} =`}</label> >{`${randomNumber1} + ${randomNumber2} =`}</label>
<input <input
className="w-24" className="w-24"
type="number" type="number"