import React, { useState, useEffect } from 'react' import { useAuth } from '../contexts/AuthContext' import { useLanguage } from '../contexts/LanguageContext' import { t } from '../i18n/translations' import { Eye, EyeOff } from 'lucide-react' import { DeepVoidBackground } from './DeepVoidBackground' // import { Input } from './ui/input' // Removed unused import import { toast } from 'sonner' import { useSystemConfig } from '../hooks/useSystemConfig' export function LoginPage() { const { language } = useLanguage() const { login, loginAdmin } = useAuth() const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [showPassword, setShowPassword] = useState(false) const [error, setError] = useState('') const [loading, setLoading] = useState(false) const [adminPassword, setAdminPassword] = useState('') const adminMode = false const { config: systemConfig } = useSystemConfig() const registrationEnabled = systemConfig?.registration_enabled !== false const [expiredToastId, setExpiredToastId] = useState(null) // Show notification if user was redirected here due to 401 useEffect(() => { if (sessionStorage.getItem('from401') === 'true') { const id = toast.warning(t('sessionExpired', language), { duration: Infinity // Keep showing until user dismisses or logs in }) setExpiredToastId(id) sessionStorage.removeItem('from401') } }, [language]) const handleAdminLogin = async (e: React.FormEvent) => { e.preventDefault() setError('') setLoading(true) const result = await loginAdmin(adminPassword) if (!result.success) { const msg = result.message || t('loginFailed', language) setError(msg) toast.error(msg) } else { // Dismiss the "login expired" toast on successful login if (expiredToastId) { toast.dismiss(expiredToastId) } } setLoading(false) } const handleLogin = async (e: React.FormEvent) => { e.preventDefault() setError('') setLoading(true) const result = await login(email, password) if (result.success) { // Dismiss the "login expired" toast on successful login. if (expiredToastId) { toast.dismiss(expiredToastId) } } else { const msg = result.message || t('loginFailed', language) setError(msg) toast.error(msg) } setLoading(false) } return (
{/* Navigation - Top Bar (Mobile/Desktop Friendly) */}
{/* Terminal Header */}
NoFx Logo

SYSTEM ACCESS

Authentication Protocol v3.0

{/* Terminal Output / Form Container */}
{/* Window Bar */}
window.location.href = '/'} title="Close / Return Home" >
login.exe
{/* Status Output */}
Initiating handshake...
Target: NOFX CORE HUB
Status: AWAITING CREDENTIALS
{adminMode ? (
setAdminPassword(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-700 text-white font-mono" placeholder="ENTER_ROOT_PASSWORD" required />
{error && (
[ERROR]: {error}
)}
) : (
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-700 text-white font-mono" placeholder="user@nofx.os" required />
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-700 text-white font-mono pr-10" placeholder="••••••••••••" required />
{error && (
{error}
)}
)}
{/* Terminal Footer Info */}
SECURE_CONNECTION: ENCRYPTED
{new Date().toISOString().split('T')[0]}
{/* Register Link */} {!adminMode && registrationEnabled && (

NEW_USER_DETECTED?{' '}

)}
) }