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'),
|
|
|
|
privateRouter = express.Router();
|
|
|
|
|
|
|
|
function controller(req, res) {
|
|
|
|
var defaultView = path.resolve(__dirname, 'views', 'private.hbs'),
|
|
|
|
paths = templates.getActiveThemePaths(req.app.get('activeTheme')),
|
|
|
|
data = {};
|
|
|
|
|
|
|
|
if (res.error) {
|
|
|
|
data.error = res.error;
|
|
|
|
}
|
|
|
|
|
|
|
|
setResponseContext(req, res);
|
|
|
|
if (paths.hasOwnProperty('private.hbs')) {
|
|
|
|
return res.render('private', data);
|
|
|
|
} else {
|
|
|
|
return res.render(defaultView, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
middleware.spamPrevention,
|
|
|
|
middleware.authenticateProtection,
|
|
|
|
controller
|
|
|
|
);
|
|
|
|
|
|
|
|
module.exports = privateRouter;
|
|
|
|
module.exports.controller = controller;
|