2016-04-11 16:58:41 +03:00
|
|
|
var path = require('path'),
|
|
|
|
express = require('express'),
|
|
|
|
middleware = require('./middleware'),
|
2016-10-11 11:36:00 +03:00
|
|
|
bodyParser = require('body-parser'),
|
2016-04-11 16:58:41 +03:00
|
|
|
templates = require('../../../controllers/frontend/templates'),
|
|
|
|
setResponseContext = require('../../../controllers/frontend/context'),
|
2016-11-08 14:33:19 +03:00
|
|
|
brute = require('../../../middleware/brute'),
|
2017-03-14 02:15:50 +03:00
|
|
|
|
2016-04-11 16:58:41 +03:00
|
|
|
privateRouter = express.Router();
|
|
|
|
|
|
|
|
function controller(req, res) {
|
2017-03-14 02:15:50 +03:00
|
|
|
var templateName = 'private',
|
|
|
|
defaultTemplate = path.resolve(__dirname, 'views', templateName + '.hbs'),
|
2017-09-12 18:31:14 +03:00
|
|
|
view = templates.pickTemplate(templateName, defaultTemplate),
|
2016-04-11 16:58:41 +03:00
|
|
|
data = {};
|
|
|
|
|
|
|
|
if (res.error) {
|
|
|
|
data.error = res.error;
|
|
|
|
}
|
|
|
|
|
|
|
|
setResponseContext(req, res);
|
2017-03-14 02:15:50 +03:00
|
|
|
|
2017-09-12 18:31:14 +03:00
|
|
|
return res.render(view, data);
|
2016-04-11 16:58:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// password-protected frontend route
|
|
|
|
privateRouter.route('/')
|
|
|
|
.get(
|
|
|
|
middleware.isPrivateSessionAuth,
|
|
|
|
controller
|
|
|
|
)
|
|
|
|
.post(
|
2016-10-11 11:36:00 +03:00
|
|
|
bodyParser.urlencoded({extended: true}),
|
2016-04-11 16:58:41 +03:00
|
|
|
middleware.isPrivateSessionAuth,
|
2016-11-08 14:33:19 +03:00
|
|
|
brute.privateBlog,
|
2016-04-11 16:58:41 +03:00
|
|
|
middleware.authenticateProtection,
|
|
|
|
controller
|
|
|
|
);
|
|
|
|
|
|
|
|
module.exports = privateRouter;
|
|
|
|
module.exports.controller = controller;
|