import React, { useState } from 'react'; import { login, getAzureLoginUrl } from '../graphService'; import { User, AppSettings } from '../types'; interface LoginFormProps { settings: AppSettings; onLoginSuccess: (user: User) => void; onCancel: () => void; } const LoginForm: React.FC = ({ settings, onLoginSuccess, onCancel }) => { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [authSource, setAuthSource] = useState<'local' | 'ldap'>('local'); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); if (!username || !password) { setError("Username and password are required."); return; } setIsLoading(true); setError(''); try { const data = await login(username, password, authSource); console.log("[LOGIN DEBUG] Server Response:", data); if (data && (data.user || data.success === true)) { // PHP might return {success: true, user: {...}} or just {user: {...}} const userObj = data.user || data; onLoginSuccess(userObj as User); } else { setError(data?.error || "Authentication failed: No user data returned."); } } catch (err: any) { console.error("[LOGIN ERROR]", err); setError(err.message || 'The server rejected these credentials.'); } finally { setIsLoading(false); } }; const handleAzureLogin = async () => { setIsLoading(true); try { const { url } = await getAzureLoginUrl(); window.location.href = url; } catch (err: any) { setError(err.message); setIsLoading(false); } }; // Safety check for settings object if (!settings) return null; return (

System Login

Secure License Repository

{error && (
{error}
)}
{settings?.azure_enabled && ( )}
{settings?.ldap_enabled && (
)}
setUsername(e.target.value)} className="w-full bg-slate-950 border border-slate-800 rounded-xl p-3 text-sm text-gray-200 focus:outline-none focus:border-cyan-500 transition-all shadow-inner" placeholder="Username" autoFocus />
setPassword(e.target.value)} className="w-full bg-slate-950 border border-slate-800 rounded-xl p-3 text-sm text-gray-200 focus:outline-none focus:border-cyan-500 transition-all shadow-inner" placeholder="••••••••" />
); }; export default LoginForm;