Restore enterprise/LDAP login mode detection

- Added /users/auth-mode public endpoint to detect LDAP status
- Updated frontend to call getAuthMode() instead of hardcoded false
- Login page now automatically switches to enterprise mode when LDAP is enabled
- Fixes missing LDAP user login UI that was previously disabled with TODO comment

This restores the functionality that was commented out earlier where the login
page would auto-detect whether to show local user list or enterprise username input.
This commit is contained in:
2026-04-26 13:27:46 +03:00
parent 53eb6b50dd
commit dc999991a5
6 changed files with 32 additions and 10 deletions

View File

@@ -155,7 +155,12 @@
"Bash(pkill -9 -f \"uvicorn backend.main\")", "Bash(pkill -9 -f \"uvicorn backend.main\")",
"Bash(pkill -9 -f \"python3.*start_servers\")", "Bash(pkill -9 -f \"python3.*start_servers\")",
"Bash(curl -v -X POST http://localhost:8916/users/login -H 'Content-Type: application/json' -d '{\"username\":\"admin\",\"password\":\"admin\"}')", "Bash(curl -v -X POST http://localhost:8916/users/login -H 'Content-Type: application/json' -d '{\"username\":\"admin\",\"password\":\"admin\"}')",
"Bash(pkill -9 -f \"uvicorn\\\\|gunicorn\")" "Bash(pkill -9 -f \"uvicorn\\\\|gunicorn\")",
"Bash(curl -s http://localhost:3000)",
"Bash(/data/programare_AI/tfm_ainventory/venv/bin/python3 -m uvicorn backend.main:app --host 0.0.0.0 --port 8916)",
"Bash(curl -s http://localhost:8916/users/)",
"Bash(pkill -9 -f \"uvicorn.*backend.main\" sleep 2 /data/programare_AI/tfm_ainventory/venv/bin/python3 -m uvicorn backend.main:app --host 0.0.0.0 --port 8916)",
"Bash(curl -s http://localhost:8916/users/auth-mode)"
] ]
} }
} }

View File

@@ -1,3 +1,2 @@
98497 105655
98498 105674
98515

View File

@@ -257,6 +257,16 @@ def login(request: Request, form_data: schemas.UserLogin, db: Session = Depends(
) )
@router.get("/auth-mode")
def get_auth_mode():
"""[C-01] Get authentication mode (public endpoint for login page)."""
config = get_ldap_config()
return {
"mode": "enterprise" if config.get("ldap_enabled") else "local",
"ldap_enabled": config.get("ldap_enabled", False)
}
@router.get("/ldap-config") @router.get("/ldap-config")
def get_ldap_settings(current_user: auth.TokenData = Depends(auth.get_current_admin)): def get_ldap_settings(current_user: auth.TokenData = Depends(auth.get_current_admin)):
"""[C-01] Get LDAP config — admin only.""" """[C-01] Get LDAP config — admin only."""

View File

@@ -87,6 +87,8 @@
} }
* { * {
@apply border-border; @apply border-border;
border-radius: 0 !important; border-radius: 0 !important;

View File

@@ -23,15 +23,15 @@ export default function LoginPage() {
const checkMode = async () => { const checkMode = async () => {
try { try {
setIsLoading(true); setIsLoading(true);
// TODO: getNetworkConfig() method not implemented in API // Get authentication mode from backend
// const config = await inventoryApi.getNetworkConfig(); const authMode = await inventoryApi.getAuthMode();
// setIsEnterprise(config.mode === 'enterprise'); setIsEnterprise(authMode.mode === 'enterprise');
setIsEnterprise(false); // Default to non-enterprise mode
const userList = await inventoryApi.getUsers(); const userList = await inventoryApi.getUsers();
setUsers(userList); setUsers(userList);
} catch (error) { } catch (error) {
console.error("Failed to load users", error); console.error("Failed to load auth mode or users", error);
setIsEnterprise(false); // Default to local mode on error
} finally { } finally {
setIsLoading(false); setIsLoading(false);
} }

View File

@@ -85,6 +85,12 @@ axiosInstance.interceptors.response.use(
); );
export const inventoryApi = { export const inventoryApi = {
getAuthMode: async () => {
const baseUrl = await getBackendUrl();
const res = await axios.get(`${baseUrl}/users/auth-mode`);
return res.data;
},
getItems: async () => { getItems: async () => {
const res = await axiosInstance.get('/items/'); const res = await axiosInstance.get('/items/');
return res.data; return res.data;