108 lines
4.8 KiB
JavaScript
108 lines
4.8 KiB
JavaScript
|
|
import React, { useState } from 'react';
|
||
|
|
import { Loader, AlertCircle, Lock, User } from 'lucide-react';
|
||
|
|
import { useAuth } from '../contexts/AuthContext';
|
||
|
|
|
||
|
|
export default function LoginForm() {
|
||
|
|
const [username, setUsername] = useState('');
|
||
|
|
const [password, setPassword] = useState('');
|
||
|
|
const [loading, setLoading] = useState(false);
|
||
|
|
const [error, setError] = useState('');
|
||
|
|
const { login } = useAuth();
|
||
|
|
|
||
|
|
const handleSubmit = async (e) => {
|
||
|
|
e.preventDefault();
|
||
|
|
setError('');
|
||
|
|
setLoading(true);
|
||
|
|
|
||
|
|
const result = await login(username, password);
|
||
|
|
|
||
|
|
if (!result.success) {
|
||
|
|
setError(result.error);
|
||
|
|
}
|
||
|
|
|
||
|
|
setLoading(false);
|
||
|
|
};
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div className="min-h-screen bg-gray-100 flex items-center justify-center p-4">
|
||
|
|
<div className="bg-white rounded-lg shadow-xl max-w-md w-full p-8">
|
||
|
|
<div className="text-center mb-8">
|
||
|
|
<div className="w-16 h-16 bg-[#0476D9] rounded-full flex items-center justify-center mx-auto mb-4">
|
||
|
|
<Lock className="w-8 h-8 text-white" />
|
||
|
|
</div>
|
||
|
|
<h1 className="text-2xl font-bold text-gray-900">CVE Dashboard</h1>
|
||
|
|
<p className="text-gray-600 mt-2">Sign in to access the dashboard</p>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
{error && (
|
||
|
|
<div className="mb-6 p-4 bg-red-50 border border-red-200 rounded-lg flex items-start gap-3">
|
||
|
|
<AlertCircle className="w-5 h-5 text-red-600 flex-shrink-0 mt-0.5" />
|
||
|
|
<p className="text-sm text-red-700">{error}</p>
|
||
|
|
</div>
|
||
|
|
)}
|
||
|
|
|
||
|
|
<form onSubmit={handleSubmit} className="space-y-6">
|
||
|
|
<div>
|
||
|
|
<label htmlFor="username" className="block text-sm font-medium text-gray-700 mb-2">
|
||
|
|
Username
|
||
|
|
</label>
|
||
|
|
<div className="relative">
|
||
|
|
<User className="w-5 h-5 text-gray-400 absolute left-3 top-1/2 transform -translate-y-1/2" />
|
||
|
|
<input
|
||
|
|
id="username"
|
||
|
|
type="text"
|
||
|
|
required
|
||
|
|
value={username}
|
||
|
|
onChange={(e) => setUsername(e.target.value)}
|
||
|
|
className="w-full pl-10 pr-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-[#0476D9] focus:border-transparent"
|
||
|
|
placeholder="Enter your username"
|
||
|
|
disabled={loading}
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div>
|
||
|
|
<label htmlFor="password" className="block text-sm font-medium text-gray-700 mb-2">
|
||
|
|
Password
|
||
|
|
</label>
|
||
|
|
<div className="relative">
|
||
|
|
<Lock className="w-5 h-5 text-gray-400 absolute left-3 top-1/2 transform -translate-y-1/2" />
|
||
|
|
<input
|
||
|
|
id="password"
|
||
|
|
type="password"
|
||
|
|
required
|
||
|
|
value={password}
|
||
|
|
onChange={(e) => setPassword(e.target.value)}
|
||
|
|
className="w-full pl-10 pr-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-[#0476D9] focus:border-transparent"
|
||
|
|
placeholder="Enter your password"
|
||
|
|
disabled={loading}
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<button
|
||
|
|
type="submit"
|
||
|
|
disabled={loading}
|
||
|
|
className="w-full py-3 bg-[#0476D9] text-white rounded-lg hover:bg-[#0360B8] transition-colors font-medium shadow-md disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
|
||
|
|
>
|
||
|
|
{loading ? (
|
||
|
|
<>
|
||
|
|
<Loader className="w-5 h-5 animate-spin" />
|
||
|
|
Signing in...
|
||
|
|
</>
|
||
|
|
) : (
|
||
|
|
'Sign In'
|
||
|
|
)}
|
||
|
|
</button>
|
||
|
|
</form>
|
||
|
|
|
||
|
|
<div className="mt-6 pt-6 border-t border-gray-200">
|
||
|
|
<p className="text-sm text-gray-500 text-center">
|
||
|
|
Default admin credentials: admin / admin123
|
||
|
|
</p>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|