120 lines
4.2 KiB
TypeScript
120 lines
4.2 KiB
TypeScript
'use client';
|
|
|
|
import { useState } from 'react';
|
|
import { useRouter } from 'next/navigation';
|
|
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 { toast } from 'sonner';
|
|
|
|
export default function EmailLoginPage() {
|
|
const router = useRouter();
|
|
const [loading, setLoading] = useState(false);
|
|
const [credentials, setCredentials] = useState({
|
|
email: '',
|
|
password: '',
|
|
host: 'mail.infomaniak.com',
|
|
port: '993'
|
|
});
|
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
setLoading(true);
|
|
|
|
try {
|
|
// Store credentials in localStorage
|
|
localStorage.setItem('imapCredentials', JSON.stringify(credentials));
|
|
|
|
// Test the connection
|
|
const response = await fetch('/api/mail/test-connection', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(credentials),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to connect to email server');
|
|
}
|
|
|
|
toast.success('Successfully connected to email server');
|
|
router.push('/mail');
|
|
} catch (error) {
|
|
console.error('Login error:', error);
|
|
toast.error('Failed to connect to email server. Please check your credentials.');
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="flex min-h-screen items-center justify-center bg-white">
|
|
<Card className="w-full max-w-md shadow-lg">
|
|
<CardHeader>
|
|
<CardTitle className="text-2xl font-bold text-gray-900">Email Login</CardTitle>
|
|
<CardDescription className="text-gray-600">
|
|
Enter your email credentials to access your mailbox
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<form onSubmit={handleSubmit} className="space-y-4">
|
|
<div className="space-y-2">
|
|
<Label htmlFor="email" className="text-gray-700">Email Address</Label>
|
|
<Input
|
|
id="email"
|
|
type="email"
|
|
placeholder="your@email.com"
|
|
value={credentials.email}
|
|
onChange={(e) => setCredentials({ ...credentials, email: e.target.value })}
|
|
required
|
|
className="border-gray-300 focus:border-blue-500 focus:ring-blue-500"
|
|
/>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<Label htmlFor="password" className="text-gray-700">Password</Label>
|
|
<Input
|
|
id="password"
|
|
type="password"
|
|
value={credentials.password}
|
|
onChange={(e) => setCredentials({ ...credentials, password: e.target.value })}
|
|
required
|
|
className="border-gray-300 focus:border-blue-500 focus:ring-blue-500"
|
|
/>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<Label htmlFor="host" className="text-gray-700">IMAP Host</Label>
|
|
<Input
|
|
id="host"
|
|
type="text"
|
|
value={credentials.host}
|
|
onChange={(e) => setCredentials({ ...credentials, host: e.target.value })}
|
|
required
|
|
className="border-gray-300 focus:border-blue-500 focus:ring-blue-500"
|
|
/>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<Label htmlFor="port" className="text-gray-700">IMAP Port</Label>
|
|
<Input
|
|
id="port"
|
|
type="text"
|
|
value={credentials.port}
|
|
onChange={(e) => setCredentials({ ...credentials, port: e.target.value })}
|
|
required
|
|
className="border-gray-300 focus:border-blue-500 focus:ring-blue-500"
|
|
/>
|
|
</div>
|
|
<Button
|
|
type="submit"
|
|
className="w-full bg-blue-600 hover:bg-blue-700 text-white"
|
|
disabled={loading}
|
|
>
|
|
{loading ? 'Connecting...' : 'Connect'}
|
|
</Button>
|
|
</form>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
);
|
|
}
|