'use client' import { useState } from 'react' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Input } from '@/components/ui/input' import { Button } from '@/components/ui/button' import { Label } from '@/components/ui/label' import { AlertCircle, CheckCircle2, Eye, EyeOff, Loader2, Mail, Lock, Monitor, Smartphone } from 'lucide-react' type Step = 'verify' | 'change' | 'success' const MAIL_DOMAIN = 'monaco-opc.com' const MAIL_SERVER = 'mail.monaco-opc.com' export default function ChangeEmailPasswordPage() { const [step, setStep] = useState('verify') const [email, setEmail] = useState('') const [currentPassword, setCurrentPassword] = useState('') const [newPassword, setNewPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [showCurrentPassword, setShowCurrentPassword] = useState(false) const [showNewPassword, setShowNewPassword] = useState(false) const [showConfirmPassword, setShowConfirmPassword] = useState(false) const [error, setError] = useState('') const [loading, setLoading] = useState(false) async function handleVerify(e: React.FormEvent) { e.preventDefault() setError('') const emailLower = email.toLowerCase().trim() if (!emailLower.endsWith(`@${MAIL_DOMAIN}`)) { setError(`Email must be an @${MAIL_DOMAIN} address.`) return } setLoading(true) try { const res = await fetch('/api/email/verify-credentials', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: emailLower, password: currentPassword }), }) const data = await res.json() if (res.status === 429) { setError(data.error || 'Too many attempts. Please try again later.') return } if (!data.valid) { setError(data.error || 'Invalid email or password.') return } setStep('change') } catch { setError('Connection error. Please try again.') } finally { setLoading(false) } } async function handleChangePassword(e: React.FormEvent) { e.preventDefault() setError('') if (newPassword.length < 8) { setError('Password must be at least 8 characters.') return } if (!/(?=.*[a-z])(?=.*[A-Z])(?=.*\d)/.test(newPassword)) { setError('Password must contain at least one uppercase letter, one lowercase letter, and one number.') return } if (newPassword !== confirmPassword) { setError('Passwords do not match.') return } setLoading(true) try { const res = await fetch('/api/email/change-password', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: email.toLowerCase().trim(), currentPassword, newPassword, }), }) const data = await res.json() if (!res.ok) { setError(data.error || 'Failed to change password.') return } setStep('success') } catch { setError('Connection error. Please try again.') } finally { setLoading(false) } } return (

Email Account

Change your @{MAIL_DOMAIN} email password

{step === 'verify' && ( Verify Your Identity Enter your email address and current password to continue.
setEmail(e.target.value)} required autoComplete="email" />
setCurrentPassword(e.target.value)} required autoComplete="current-password" />
{error && (
{error}
)}
)} {step === 'change' && ( Set New Password Choose a new password for {email.toLowerCase().trim()}. Must be at least 8 characters with uppercase, lowercase, and a number.
setNewPassword(e.target.value)} required autoComplete="new-password" minLength={8} />
setConfirmPassword(e.target.value)} required autoComplete="new-password" minLength={8} />
{error && (
{error}
)}
)} {step === 'success' && (

Password Changed Successfully

Your password for {email.toLowerCase().trim()} has been updated. Use your new password to sign in to your email.

Mail Client Setup Use these settings to add your email account to any mail app.

Incoming Mail (IMAP)

Server
{MAIL_SERVER}
Port
993
Security
SSL/TLS
Username
{email.toLowerCase().trim()}

Outgoing Mail (SMTP)

Server
{MAIL_SERVER}
Port
587
Security
STARTTLS
Username
{email.toLowerCase().trim()}

Mobile Apps

  • iPhone/iPad: Settings > Mail > Accounts > Add Account > Other
  • Gmail App: Settings > Add Account > Other
  • Outlook App: Settings > Add Email Account

Desktop Apps

  • Apple Mail: Mail > Add Account > Other Mail Account
  • Outlook: File > Add Account
  • Thunderbird: Account Settings > Account Actions > Add Mail Account
)}
) }