| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- /*
- * GET users listing.
- */
- import express = require('express');
- const router = express.Router();
- import RouterUtils from '../src/RouterUtils';
- 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) => {
- if (!req.isUserLogged)
- return RouterUtils.Redirect(res, "/login");
- req.ldapManager.GetInstance().then(ldap => ldap.GetTree()).then(root => {
- res.render("index", {
- tree: root.GetChildren()[0],
- DnToLnk: DnToLink
- });
- });
- });
- router.get('/home', (req, res) => {
- if (!req.isUserLogged)
- return RouterUtils.Redirect(res, "/login");
- res.render('homePage', {});
- });
- export default router;
|