import React, { useEffect, useState } from 'react' import { Eye, EyeOff } from 'lucide-react' import { useNavigate } from 'react-router-dom' import PasswordChecklist from 'react-password-checklist' import { toast } from 'sonner' import { useAuth } from '../../contexts/AuthContext' import { useLanguage } from '../../contexts/LanguageContext' import { t } from '../../i18n/translations' import { getSystemConfig } from '../../lib/config' import { DeepVoidBackground } from '../common/DeepVoidBackground' import { RegistrationDisabled } from './RegistrationDisabled' import { WhitelistFullPage } from '../common/WhitelistFullPage' export function RegisterPage() { const { language } = useLanguage() const { register } = useAuth() const navigate = useNavigate() const [view, setView] = useState<'register' | 'whitelist-full'>('register') const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [betaCode, setBetaCode] = useState('') const [betaMode, setBetaMode] = useState(false) const [registrationEnabled, setRegistrationEnabled] = useState(true) const [error, setError] = useState('') const [loading, setLoading] = useState(false) const [passwordValid, setPasswordValid] = useState(false) const [showPassword, setShowPassword] = useState(false) const [showConfirmPassword, setShowConfirmPassword] = useState(false) useEffect(() => { getSystemConfig() .then((config) => { setBetaMode(config.beta_mode || false) setRegistrationEnabled(config.initialized === false) }) .catch((err) => { console.error('Failed to fetch system config:', err) }) }, []) if (!registrationEnabled) { return } if (view === 'whitelist-full') { return setView('register')} /> } const handleRegister = async (e: React.FormEvent) => { e.preventDefault() setError('') if (!passwordValid) { setError(t('passwordNotMeetRequirements', language)) return } if (betaMode && !betaCode.trim()) { setError('内测期间,注册需要提供内测码') return } setLoading(true) try { const result = await register( email, password, betaCode.trim() || undefined ) const isWhitelistError = (msg: string) => { const lowerMsg = msg.toLowerCase() return ( lowerMsg.includes('whitelist') || lowerMsg.includes('capacity') || lowerMsg.includes('limit') || lowerMsg.includes('permission denied') || lowerMsg.includes('not on whitelist') ) } if (!result.success) { const msg = result.message || t('registrationFailed', language) if (isWhitelistError(msg)) { setView('whitelist-full') return } setError(msg) toast.error(msg) } // success path is handled in AuthContext (auto login + navigation) } catch (e) { console.error('Registration error:', e) const errorMsg = e instanceof Error ? e.message : 'Registration failed due to server error' const lowerMsg = errorMsg.toLowerCase() if ( lowerMsg.includes('whitelist') || lowerMsg.includes('capacity') || lowerMsg.includes('limit') || lowerMsg.includes('permission denied') || lowerMsg.includes('not on whitelist') ) { setView('whitelist-full') return } setError(errorMsg) toast.error(errorMsg) } finally { setLoading(false) } } return ( navigate('/')} className="flex items-center gap-2 text-zinc-500 hover:text-white transition-colors group px-3 py-1.5 rounded border border-transparent hover:border-zinc-700 bg-black/20 backdrop-blur-sm" > < ABORT_REGISTRATION NEW_USER ONBOARDING Initializing Registration Sequence... navigate('/')} title="Close / Return Home" > ➜ setup_account.sh ➜ System Check: READY ➜ Mode: {betaMode ? 'CLOSED_BETA CA1' : 'PUBLIC'} {t('email', language)} setEmail(e.target.value)} className="w-full bg-black/50 border border-zinc-700 rounded px-4 py-3 text-sm focus:border-nofx-gold focus:ring-1 focus:ring-nofx-gold/50 outline-none transition-all placeholder-zinc-800 text-white font-mono" placeholder="user@nofx.os" required /> {t('password', language)} setPassword(e.target.value)} className="w-full bg-black/50 border border-zinc-700 rounded px-4 py-3 text-sm focus:border-nofx-gold focus:ring-1 focus:ring-nofx-gold/50 outline-none transition-all placeholder-zinc-800 text-white font-mono pr-10" placeholder="••••••••" required /> setShowPassword(!showPassword)} className="absolute right-3 top-1/2 -translate-y-1/2 text-zinc-600 hover:text-zinc-400 transition-colors" > {showPassword ? : } {t('confirmPassword', language)} setConfirmPassword(e.target.value)} className="w-full bg-black/50 border border-zinc-700 rounded px-4 py-3 text-sm focus:border-nofx-gold focus:ring-1 focus:ring-nofx-gold/50 outline-none transition-all placeholder-zinc-800 text-white font-mono pr-10" placeholder="••••••••" required /> setShowConfirmPassword(!showConfirmPassword) } className="absolute right-3 top-1/2 -translate-y-1/2 text-zinc-600 hover:text-zinc-400 transition-colors" > {showConfirmPassword ? ( ) : ( )} Password Strength Protocol setPasswordValid(isValid)} iconSize={10} /> {betaMode && ( Priority Access Code setBetaCode( e.target.value.replace(/[^a-z0-9]/gi, '').toLowerCase() ) } className="w-full bg-black/50 border border-zinc-700 rounded px-4 py-3 text-sm focus:border-nofx-gold focus:ring-1 focus:ring-nofx-gold/50 outline-none transition-all placeholder-zinc-800 text-white font-mono tracking-widest" placeholder="XXXXXX" maxLength={6} required={betaMode} /> * CASE SENSITIVE ALPHANUMERIC )} {error && ( [REGISTRATION_ERROR]: {error} )} {loading ? ( INITIALIZING... ) : ( <> CREATE_ACCOUNT -> > )} ENCRYPTION: AES-256 SECURE_REGISTRY EXISTING_OPERATOR?{' '} navigate('/login')} className="text-nofx-gold hover:underline hover:text-yellow-300 transition-colors ml-1 uppercase" > ACCESS TERMINAL navigate('/')} className="text-[10px] text-zinc-600 hover:text-red-500 transition-colors uppercase tracking-widest hover:underline decoration-red-500/30 font-mono" > [ ABORT_REGISTRATION_RETURN_HOME ] ) }
Initializing Registration Sequence...
* CASE SENSITIVE ALPHANUMERIC
EXISTING_OPERATOR?{' '} navigate('/login')} className="text-nofx-gold hover:underline hover:text-yellow-300 transition-colors ml-1 uppercase" > ACCESS TERMINAL