A web application allowing people to create an account, configure a profile, and share a list of URLs on that profile.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

76 lines
2.1 KiB

// admin.js
// Copyright (C) 2021 Digital Telepresence, LLC
// License: Apache-2.0
'use strict';
const DTP_COMPONENT_NAME = 'admin';
const path = require('path');
const express = require('express');
const mongoose = require('mongoose');
const User = mongoose.model('User');
const { SiteError, SiteController } = require('../../lib/site-lib');
class AdminController extends SiteController {
constructor (dtp) {
super(dtp, DTP_COMPONENT_NAME);
}
async start ( ) {
const { otpAuth: otpAuthService } = this.dtp.services;
const router = express.Router();
this.dtp.app.use('/admin', router);
router.use(
async (req, res, next) => {
res.locals.currentView = 'admin';
res.locals.adminView = 'home';
if (!req.user || !req.user.flags.isAdmin) {
return next(new SiteError(403, 'Administrative privileges required'));
}
return next();
},
otpAuthService.middleware('Admin', {
adminRequired: true,
otpRequired: true,
otpRedirectURL: '/admin',
}),
);
router.use('/host',await this.loadChild(path.join(__dirname, 'admin', 'host')));
router.use('/job-queue',await this.loadChild(path.join(__dirname, 'admin', 'job-queue')));
router.use('/link',await this.loadChild(path.join(__dirname, 'admin', 'link')));
router.use('/newsletter',await this.loadChild(path.join(__dirname, 'admin', 'newsletter')));
router.use('/settings',await this.loadChild(path.join(__dirname, 'admin', 'settings')));
router.use('/user', await this.loadChild(path.join(__dirname, 'admin', 'user')));
router.get('/', this.getHomeView.bind(this));
return router;
}
async getHomeView (req, res) {
const { link: linkService } = this.dtp.services;
res.locals.stats = {
memberCount: await User.estimatedDocumentCount(),
linkCount: await linkService.getTotalCount(),
};
res.render('admin/index');
}
}
module.exports = {
slug: 'admin',
name: 'admin',
create: async (dtp) => {
let controller = new AdminController(dtp);
return controller;
},
};