From 1a4805bfe904bfea74cc3b9458acd207b082624c Mon Sep 17 00:00:00 2001 From: Dryusdan Date: Sun, 23 Jul 2017 17:37:50 +0200 Subject: [PATCH] Remove basic admin area --- app.js | 11 ++++++----- lib/router.js | 49 ------------------------------------------------- 2 files changed, 6 insertions(+), 54 deletions(-) diff --git a/app.js b/app.js index b17ceaa..5e8e67b 100644 --- a/app.js +++ b/app.js @@ -56,14 +56,15 @@ class Nodezzarella { var routes = require("./lib/router"); log.info("HTTP server listening on port", config.appPort); log.info("Application ready"); - app.use(cookieParser()); // read cookies (needed for auth) - app.use(bodyParser.urlencoded({ extended: false })); // get information from url-encoded data - app.use(bodyParser.json()); // get information from html forms + app.set('trust proxy', 1); + app.use(cookieParser()); + app.use(bodyParser.urlencoded({ extended: true })); + app.use(bodyParser.json()); app.use(session({ secret: 'Nodezzarella', - resave: false, + resave: true, saveUninitialized: true, - cookie: { secure: true } + cookie: { secure: false, maxAge: 3600*24*31 } })) app.use(config.webroot || "/", routes); app.use(function(req, res, next) { diff --git a/lib/router.js b/lib/router.js index 996894f..a5353f1 100644 --- a/lib/router.js +++ b/lib/router.js @@ -34,55 +34,6 @@ router.get("/", function(req, res){ }); }); -router.get("/admin/", function(req, res){ - var categories = new Categories(); - if(req.session.authenticated === true){ - res.redirect('/admin/dashboard') - } - else{ - categories.getNav().then(data => { - fs.readFile('./views/admin/login.hbs', 'utf-8', (error, source) => { - var template = hbs.compile(source); - res.setHeader("Content-type", "text/html"); - var tplData = { - "blogName": config.siteTitle, - "title": config.siteHomeTitle, - "nav": data, - "content": source, - }; - res.render('templateAdmin.hbs', tplData); - }); - }).catch(err => { - log.debug(err); - res.setHeader("Content-type", "text/plain"); - res.end("erreur"); - }); - } -}); - -router.post("/admin/", function(req, res){ - if(req.body.login && req.body.login === config.login && req.body.password && req.body.password === config.password){ - req.session.authenticated = true; - res.redirect('/admin/dashboard'); - - } - else{ - res.redirect('/admin/'); - } -}); - -router.get("/admin/dashboard", function(req, res){ - log.debug(req.session); - if(req.session.authenticated === true){ - res.setHeader("Content-type", "text/plain"); - res.end("erreur"); - } - else{ - res.redirect('/admin/'); - } -}); - - router.get("/:uri/", function(req, res){ var categories = new Categories(); Promise.all([