import React, { useEffect, useState } from 'react'; import { Button, Form, Grid, Header, Image, Segment } from 'semantic-ui-react'; import { API, showError, showInfo, showSuccess } from '../helpers'; import Turnstile from 'react-turnstile'; const PasswordResetForm = () => { const [inputs, setInputs] = useState({ email: '', }); const { email } = inputs; const [loading, setLoading] = useState(false); const [turnstileEnabled, setTurnstileEnabled] = useState(false); const [turnstileSiteKey, setTurnstileSiteKey] = useState(''); const [turnstileToken, setTurnstileToken] = useState(''); useEffect(() => { let status = localStorage.getItem('status'); if (status) { status = JSON.parse(status); if (status.turnstile_check) { setTurnstileEnabled(true); setTurnstileSiteKey(status.turnstile_site_key); } } }, []); function handleChange(e) { const { name, value } = e.target; setInputs((inputs) => ({ ...inputs, [name]: value })); } async function handleSubmit(e) { if (!email) return; if (turnstileEnabled && turnstileToken === '') { showInfo('请稍后几秒重试,Turnstile 正在检查用户环境!'); return; } setLoading(true); const res = await API.get( `/api/reset_password?email=${email}&turnstile=${turnstileToken}` ); const { success, message } = res.data; if (success) { showSuccess('重置邮件发送成功,请检查邮箱!'); setInputs({ ...inputs, email: '' }); } else { showError(message); } setLoading(false); } return (
密码重置
{turnstileEnabled ? ( { setTurnstileToken(token); }} /> ) : ( <> )}
); }; export default PasswordResetForm;