/* * Global Captcha that is valid sitewide * via api/captcha * Displayed in an Alert */ import React, { useState } from 'react'; import { t } from 'ttag'; import Captcha from './Captcha'; import { requestSolveCaptcha, requestBanMe, } from '../store/actions/fetch'; const GlobalCaptcha = ({ close }) => { const [errors, setErrors] = useState([]); const [legit, setLegit] = useState(false); // used to be able to force Captcha rerender on error const [captKey, setCaptKey] = useState(Date.now()); return (
{ e.preventDefault(); // ---- const test = document.getElementById('void-bot'); if (!legit || test) { await requestBanMe((legit) ? 1 : 2); } // ---- const text = e.target.captcha.value; const captchaid = e.target.captchaid.value; const { errors: resErrors } = await requestSolveCaptcha( text, captchaid, ); if (resErrors) { setCaptKey(Date.now()); setErrors(resErrors); } else { close(); } }} > {errors.map((error) => (

{t`Error`}: {error}

))}

 

); }; export default React.memo(GlobalCaptcha);