/* Copyright (c) 2025 Tethys Plex This file is part of Veloera. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import React, { useEffect, useState } from 'react'; import { Button, Form, Grid, Header, Image, Segment } from 'semantic-ui-react'; import { API, copy, showError, showNotice } from '../helpers'; import { useSearchParams } from 'react-router-dom'; const PasswordResetConfirm = () => { const [inputs, setInputs] = useState({ email: '', token: '', }); const { email, token } = inputs; const [loading, setLoading] = useState(false); const [disableButton, setDisableButton] = useState(false); const [countdown, setCountdown] = useState(30); const [newPassword, setNewPassword] = useState(''); const [searchParams, setSearchParams] = useSearchParams(); useEffect(() => { let token = searchParams.get('token'); let email = searchParams.get('email'); setInputs({ token, email, }); }, []); useEffect(() => { let countdownInterval = null; if (disableButton && countdown > 0) { countdownInterval = setInterval(() => { setCountdown(countdown - 1); }, 1000); } else if (countdown === 0) { setDisableButton(false); setCountdown(30); } return () => clearInterval(countdownInterval); }, [disableButton, countdown]); async function handleSubmit(e) { setDisableButton(true); if (!email) return; setLoading(true); const res = await API.post(`/api/user/reset`, { email, token, }); const { success, message } = res.data; if (success) { let password = res.data.data; setNewPassword(password); await copy(password); showNotice(`新密码已复制到剪贴板:${password}`); } else { showError(message); } setLoading(false); } return (
密码重置确认
{newPassword && ( { e.target.select(); navigator.clipboard.writeText(newPassword); showNotice(`密码已复制到剪贴板:${newPassword}`); }} /> )}
); }; export default PasswordResetConfirm;