mirror of
https://github.com/khoaliber/dockhand.git
synced 2026-03-06 05:39:05 +00:00
Initial commit
This commit is contained in:
37
routes/api/auth/ldap/[id]/test/+server.ts
Normal file
37
routes/api/auth/ldap/[id]/test/+server.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
import { testLdapConnection } from '$lib/server/auth';
|
||||
import { authorize } from '$lib/server/authorize';
|
||||
import { getLdapConfig } from '$lib/server/db';
|
||||
|
||||
// POST /api/auth/ldap/[id]/test - Test LDAP connection
|
||||
export const POST: RequestHandler = async ({ params, cookies }) => {
|
||||
const auth = await authorize(cookies);
|
||||
|
||||
// Allow access when auth is disabled (setup mode) or when user is admin
|
||||
if (auth.authEnabled && (!auth.isAuthenticated || !auth.isAdmin)) {
|
||||
return json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
if (!auth.isEnterprise) {
|
||||
return json({ error: 'Enterprise license required' }, { status: 403 });
|
||||
}
|
||||
|
||||
const id = parseInt(params.id!, 10);
|
||||
if (isNaN(id)) {
|
||||
return json({ error: 'Invalid ID' }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const config = await getLdapConfig(id);
|
||||
if (!config) {
|
||||
return json({ error: 'LDAP configuration not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
const result = await testLdapConnection(id);
|
||||
return json(result);
|
||||
} catch (error) {
|
||||
console.error('Failed to test LDAP connection:', error);
|
||||
return json({ error: 'Failed to test LDAP connection' }, { status: 500 });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user