import React, { useState } from 'react' import { useAuth } from '../contexts/AuthContext' import { useLanguage } from '../contexts/LanguageContext' import { t } from '../i18n/translations' import { Header } from './Header' import { ArrowLeft, KeyRound, Eye, EyeOff } from 'lucide-react' export function ResetPasswordPage() { const { language } = useLanguage() const { resetPassword } = useAuth() const [email, setEmail] = useState('') const [newPassword, setNewPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [otpCode, setOtpCode] = useState('') const [error, setError] = useState('') const [success, setSuccess] = useState(false) const [loading, setLoading] = useState(false) const [showPassword, setShowPassword] = useState(false) const [showConfirmPassword, setShowConfirmPassword] = useState(false) const handleResetPassword = async (e: React.FormEvent) => { e.preventDefault() setError('') setSuccess(false) // 验证两次密码是否一致 if (newPassword !== confirmPassword) { setError(t('passwordMismatch', language)) return } setLoading(true) const result = await resetPassword(email, newPassword, otpCode) if (result.success) { setSuccess(true) // 3秒后跳转到登录页面 setTimeout(() => { window.history.pushState({}, '', '/login') window.dispatchEvent(new PopStateEvent('popstate')) }, 3000) } else { setError(result.message || t('resetPasswordFailed', language)) } setLoading(false) } return (
{/* Back to Login */} {/* Logo */}

{t('resetPasswordTitle', language)}

使用邮箱和 Google Authenticator 重置密码

{/* Reset Password Form */}
{success ? (

{t('resetPasswordSuccess', language)}

3秒后将自动跳转到登录页面...

) : (
setEmail(e.target.value)} className="w-full px-3 py-2 rounded" style={{ background: '#0B0E11', border: '1px solid #2B3139', color: '#EAECEF', }} placeholder={t('emailPlaceholder', language)} required />
setNewPassword(e.target.value)} className="w-full px-3 py-2 pr-10 rounded" style={{ background: '#0B0E11', border: '1px solid #2B3139', color: '#EAECEF', }} placeholder={t('newPasswordPlaceholder', language)} required minLength={6} />
setConfirmPassword(e.target.value)} className="w-full px-3 py-2 pr-10 rounded" style={{ background: '#0B0E11', border: '1px solid #2B3139', color: '#EAECEF', }} placeholder={t('confirmPasswordPlaceholder', language)} required minLength={6} />
📱

打开 Google Authenticator 获取6位验证码

setOtpCode(e.target.value.replace(/\D/g, '').slice(0, 6)) } className="w-full px-3 py-2 rounded text-center text-2xl font-mono" style={{ background: '#0B0E11', border: '1px solid #2B3139', color: '#EAECEF', }} placeholder={t('otpPlaceholder', language)} maxLength={6} required />
{error && (
{error}
)}
)}
) }