|
|
@@ -1,11 +1,48 @@
|
|
|
/*
|
|
|
- * GET home page.
|
|
|
+ * GET users listing.
|
|
|
*/
|
|
|
import express = require('express');
|
|
|
const router = express.Router();
|
|
|
+import Security from '../src/Security';
|
|
|
+import { ILDAPManager } from '../src/ldapInterface';
|
|
|
+import LDAPEntry from '../src/LDAPEntry';
|
|
|
+import ConfigManager, { LDAPAttribute, LDAPCategory } from '../src/ConfigLoader';
|
|
|
+
|
|
|
+function GetCurrentCategory(req: express.Request, defaultResult: LDAPCategory): LDAPCategory|null {
|
|
|
+ if (!req.query["category"])
|
|
|
+ return null;
|
|
|
+ let query = Array.isArray(req.query["category"]) ? req.query["category"][0] : req.query["category"];
|
|
|
+ return LinkToCategory(query.toString()) || defaultResult;
|
|
|
+}
|
|
|
+
|
|
|
+function LinkToCategory(query: string): LDAPCategory | null {
|
|
|
+ return ConfigManager.GetInstance().GetCategoryByName(decodeURIComponent(query));
|
|
|
+}
|
|
|
+
|
|
|
+function CategoryToLink(category: LDAPCategory): string {
|
|
|
+ return encodeURIComponent(category.GetName());
|
|
|
+}
|
|
|
+
|
|
|
+function DnToLink(dn: string): string {
|
|
|
+ return encodeURIComponent(dn);
|
|
|
+}
|
|
|
|
|
|
router.get('/', (req: express.Request, res: express.Response) => {
|
|
|
- res.render('index', { title: 'Express' });
|
|
|
+ if (!Security.requireLoggedUser(req, res))
|
|
|
+ return;
|
|
|
+ req.ldapManager.GetInstance().then((ldap: ILDAPManager): void => {
|
|
|
+ ldap.GetTree().then(root => {
|
|
|
+ res.render("index", {
|
|
|
+ tree: root.GetChildren()[0],
|
|
|
+ DnToLnk: DnToLink
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+});
|
|
|
+router.get('/home', (req, res) => {
|
|
|
+ if (!Security.requireLoggedUser(req, res))
|
|
|
+ return;
|
|
|
+ res.send("Hello, world");
|
|
|
});
|
|
|
|
|
|
-export default router;
|
|
|
+export default router;
|