6 changed files with 168 additions and 114 deletions
@ -0,0 +1,21 @@ |
|||
{ |
|||
// Use IntelliSense to learn about possible attributes. |
|||
// Hover to view descriptions of existing attributes. |
|||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 |
|||
"version": "0.2.0", |
|||
"configurations": [ |
|||
{ |
|||
"type": "pwa-node", |
|||
"request": "launch", |
|||
"name": "Launch Program", |
|||
"skipFiles": [ |
|||
"<node_internals>/**" |
|||
], |
|||
"program": "${workspaceFolder:dtp-sites}/dtp-sites.js", |
|||
"console": "integratedTerminal", |
|||
"env": { |
|||
"HTTP_BIND_PORT": "3333" |
|||
} |
|||
} |
|||
] |
|||
} |
@ -0,0 +1,68 @@ |
|||
// admin.js
|
|||
// Copyright (C) 2021 Digital Telepresence, LLC
|
|||
// All Rights Reserved
|
|||
|
|||
'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('/domain',await this.loadChild(path.join(__dirname, 'admin', 'domain'))); |
|||
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('/user', await this.loadChild(path.join(__dirname, 'admin', 'user'))); |
|||
|
|||
router.get('/', this.getHomeView.bind(this)); |
|||
|
|||
return router; |
|||
} |
|||
|
|||
async getHomeView (req, res) { |
|||
res.locals.stats = { |
|||
memberCount: await User.estimatedDocumentCount(), |
|||
}; |
|||
res.render('admin/index'); |
|||
} |
|||
} |
|||
|
|||
module.exports = async (dtp) => { |
|||
let controller = new AdminController(dtp); |
|||
return controller; |
|||
}; |
Loading…
Reference in new issue