From 1ca055a526aeddc2b9a4bb2b64945ab048b65278 Mon Sep 17 00:00:00 2001 From: Evert Date: Sun, 27 Aug 2017 21:39:30 +0300 Subject: [PATCH] start admin panel --- package.json | 10 +++++---- server/routes/admin.js | 49 ++++++++++++++++++++++++++++++++++++++++++ server/routes/index.js | 2 ++ src/script/admin.js | 3 +++ src/style/admin.styl | 37 +++++++++++++++++++++++++++++++ views/admin/index.pug | 6 ++++++ views/admin/layout.pug | 27 +++++++++++++++++++++++ views/admin/oauth2.pug | 6 ++++++ 8 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 server/routes/admin.js create mode 100644 src/script/admin.js create mode 100644 src/style/admin.styl create mode 100644 views/admin/index.pug create mode 100644 views/admin/layout.pug create mode 100644 views/admin/oauth2.pug diff --git a/package.json b/package.json index ec738cd..86c8af4 100644 --- a/package.json +++ b/package.json @@ -8,11 +8,13 @@ "test": "echo \"Error: no test specified\" && exit 1", "css": "mkdir -p build/style && stylus -o build/style src/style/*.styl", "css:watch": "mkdir -p build/style && stylus -w -o build/style src/style/*.styl", - "js": "mkdir -p build/script && browserify src/script/main.js -o build/script/main.js && uglifyjs --overwrite build/script/main.js", - "js:watch": "mkdir -p build/script && watchify src/script/main.js -o build/script/main.js", - "watch": "concurrently --kill-others \"npm run css:watch\" \"npm run js:watch\"", + "js:main": "mkdir -p build/script && browserify src/script/main.js -o build/script/main.js && uglifyjs --overwrite build/script/main.js", + "js:main:watch": "mkdir -p build/script && watchify src/script/main.js -o build/script/main.js", + "js:admin": "mkdir -p build/script && browserify src/script/admin.js -o build/script/admin.js && uglifyjs --overwrite build/script/admin.js", + "js:admin:watch": "mkdir -p build/script && watchify src/script/admin.js -o build/script/admin.js", + "watch": "concurrently --kill-others \"npm run css:watch\" \"npm run js:main:watch\" \"npm run js:admin:watch\"", "clean": "rm -rf build/", - "build": "npm run clean && npm run css && npm run js" + "build": "npm run clean && npm run css && npm run js:main && npm run js:admin" }, "repository": { "type": "git", diff --git a/server/routes/admin.js b/server/routes/admin.js new file mode 100644 index 0000000..c8d42ec --- /dev/null +++ b/server/routes/admin.js @@ -0,0 +1,49 @@ +import express from 'express' +import multiparty from 'multiparty' +import config from '../../scripts/load-config' +import wrap from '../../scripts/asyncRoute' +import API from '../api' +import News from '../api/news' +import Image from '../api/image' +import APIExtern from '../api/external' + +const router = express.Router() +const apiRouter = express.Router() + +router.use(wrap(async (req, res, next) => { + if (!req.session.user) return res.redirect('/login') + + if (!req.session.privilege) { + let u = await API.User.get(req.session.user) + req.session.privilege = u.nw_privilege + } + + if (req.session.user && req.session.privilege !== 5) { + return res.redirect('/login') + } + + res.locals.server_time = process.uptime() + next() +})) + +/* ========= + * VIEWS + * ========= + */ + +router.get('/', (req, res) => { + res.render('admin/index') +}) + +router.get('/oauth2', wrap(async (req, res) => { + res.render('admin/oauth2') +})) + +/* ======= + * API + * ======= + */ + +router.use('/api', apiRouter) + +module.exports = router diff --git a/server/routes/index.js b/server/routes/index.js index c328e76..c4b0fb0 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -11,6 +11,7 @@ import emailer from '../api/emailer' import apiRouter from './api' import oauthRouter from './oauth2' +import adminRouter from './admin' let router = express.Router() @@ -703,6 +704,7 @@ router.get('/activate/:token', wrap(async (req, res) => { })) router.use('/api', apiRouter) +router.use('/admin', adminRouter) /* NO ROUTES BEYOND THIS POINT diff --git a/src/script/admin.js b/src/script/admin.js new file mode 100644 index 0000000..33414da --- /dev/null +++ b/src/script/admin.js @@ -0,0 +1,3 @@ +window.$ = require('jquery') + +$(window).ready(function () {}) diff --git a/src/style/admin.styl b/src/style/admin.styl new file mode 100644 index 0000000..5e66db0 --- /dev/null +++ b/src/style/admin.styl @@ -0,0 +1,37 @@ +body + margin: 0 + background-color: #f5f5f5 + font-family: Helvetica + +nav + display: block + height: 60px + background-color: #6b6b6b + border-bottom: 5px solid #383838 + ul + display: inline-block + margin: 0 + padding: 0 + list-style-type: none + &.right + float: right + li + height: 60px + display: inline-block + a + font-size: 180% + padding: 15px + line-height: 2 + color: #ddd + text-decoration: none + text-transform: uppercase + font-weight: bold + &:hover + background-color: #868686 + +.wrapper + min-height: 100vh + overflow: hidden + .container + overflow: hidden + padding: 10px diff --git a/views/admin/index.pug b/views/admin/index.pug new file mode 100644 index 0000000..1eae901 --- /dev/null +++ b/views/admin/index.pug @@ -0,0 +1,6 @@ +extends layout.pug + +block body + .container + .content + h1 Welcome to the Admin Panel diff --git a/views/admin/layout.pug b/views/admin/layout.pug new file mode 100644 index 0000000..f9a74ef --- /dev/null +++ b/views/admin/layout.pug @@ -0,0 +1,27 @@ +html + head + meta(charset="utf8") + link(rel="stylesheet", type="text/css", href="/style/admin.css") + script. + window.variables = { + server_time: parseInt('#{server_time}') + }; + script(src="/script/admin.js") + title + block title + |Icy Network - Administration + body + block navigation + nav + ul + li + a.logo(href="/") Icy Network + li + a(href="/admin/") Home + li + a(href="/admin/oauth2/") OAuth2 + ul.right + li + a(href="/user/manage") #{user.display_name} + .wrapper + block body diff --git a/views/admin/oauth2.pug b/views/admin/oauth2.pug new file mode 100644 index 0000000..06156c2 --- /dev/null +++ b/views/admin/oauth2.pug @@ -0,0 +1,6 @@ +extends layout.pug + +block body + .container + .content + h1 Manage OAuth2 Clients