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'),
|
2017-11-10 15:44:29 +03:00
|
|
|
renderer = require('../../../controllers/frontend/renderer'),
|
2017-12-06 19:37:54 +03:00
|
|
|
brute = require('../../../web/middleware/brute'),
|
2017-03-14 02:15:50 +03:00
|
|
|
|
2017-11-05 15:45:43 +03:00
|
|
|
templateName = 'private',
|
|
|
|
|
2016-04-11 16:58:41 +03:00
|
|
|
privateRouter = express.Router();
|
|
|
|
|
2017-11-05 15:45:43 +03:00
|
|
|
function _renderer(req, res) {
|
2017-11-10 15:44:29 +03:00
|
|
|
// Note: this is super similar to the config middleware used in channels
|
|
|
|
// @TODO refactor into to something explicit & DRY this up
|
|
|
|
res._route = {
|
|
|
|
type: 'custom',
|
|
|
|
templateName: templateName,
|
|
|
|
defaultTemplate: path.resolve(__dirname, 'views', templateName + '.hbs')
|
|
|
|
};
|
|
|
|
|
2017-11-05 15:45:43 +03:00
|
|
|
// Renderer begin
|
|
|
|
// Format data
|
|
|
|
var data = {};
|
2016-04-11 16:58:41 +03:00
|
|
|
|
|
|
|
if (res.error) {
|
|
|
|
data.error = res.error;
|
|
|
|
}
|
|
|
|
|
2017-11-05 15:45:43 +03:00
|
|
|
// Render Call
|
2017-11-10 15:44:29 +03:00
|
|
|
return renderer(req, res, data);
|
2016-04-11 16:58:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// password-protected frontend route
|
2017-11-10 15:44:29 +03:00
|
|
|
privateRouter
|
|
|
|
.route('/')
|
2016-04-11 16:58:41 +03:00
|
|
|
.get(
|
|
|
|
middleware.isPrivateSessionAuth,
|
2017-11-05 15:45:43 +03:00
|
|
|
_renderer
|
2016-04-11 16:58:41 +03:00
|
|
|
)
|
|
|
|
.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,
|
2017-11-05 15:45:43 +03:00
|
|
|
_renderer
|
2016-04-11 16:58:41 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
module.exports = privateRouter;
|
2017-11-05 15:45:43 +03:00
|
|
|
module.exports.renderer = _renderer;
|