mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
abaf0461cf
refs #5091, refs #9192 - There are several theme template "renderers" all over the codebase - Some are in apps, and were called "controllers" - One is in error handling - All of them now have comments marking out how they share logic/steps - Other comments describe routes & controllers where they live
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
var path = require('path'),
|
|
express = require('express'),
|
|
middleware = require('./middleware'),
|
|
bodyParser = require('body-parser'),
|
|
templates = require('../../../controllers/frontend/templates'),
|
|
setResponseContext = require('../../../controllers/frontend/context'),
|
|
brute = require('../../../middleware/brute'),
|
|
|
|
templateName = 'private',
|
|
defaultTemplate = path.resolve(__dirname, 'views', templateName + '.hbs'),
|
|
|
|
privateRouter = express.Router();
|
|
|
|
function _renderer(req, res) {
|
|
// Renderer begin
|
|
// Format data
|
|
var data = {};
|
|
|
|
if (res.error) {
|
|
data.error = res.error;
|
|
}
|
|
|
|
// Context
|
|
setResponseContext(req, res);
|
|
|
|
// Template
|
|
res.template = templates.pickTemplate(templateName, defaultTemplate);
|
|
|
|
// Render Call
|
|
return res.render(res.template, data);
|
|
}
|
|
|
|
// password-protected frontend route
|
|
privateRouter.route('/')
|
|
.get(
|
|
middleware.isPrivateSessionAuth,
|
|
_renderer
|
|
)
|
|
.post(
|
|
bodyParser.urlencoded({extended: true}),
|
|
middleware.isPrivateSessionAuth,
|
|
brute.privateBlog,
|
|
middleware.authenticateProtection,
|
|
_renderer
|
|
);
|
|
|
|
module.exports = privateRouter;
|
|
module.exports.renderer = _renderer;
|