Merge branch 'master' of github.com:designcreateplay/NodeBB

v1.18.x
Julian Lam 11 years ago
commit f1412193ef

@ -97,6 +97,8 @@
notifications = require('./src/notifications'), notifications = require('./src/notifications'),
upgrade = require('./src/upgrade'); upgrade = require('./src/upgrade');
templates.setGlobal('relative_path', nconf.get('relative_path'));
upgrade.check(function(schema_ok) { upgrade.check(function(schema_ok) {
if (schema_ok || nconf.get('check-schema') === false) { if (schema_ok || nconf.get('check-schema') === false) {
websockets.init(SocketIO); websockets.init(SocketIO);

@ -23,7 +23,7 @@ var socket,
} else { } else {
var max_reconnection_attemps = 5; var max_reconnection_attemps = 5;
var reconnection_delay = 200; var reconnection_delay = 200;
socket = io.connect(RELATIVE_PATH, { socket = io.connect('', {
'max reconnection attempts': max_reconnection_attemps, 'max reconnection attempts': max_reconnection_attemps,
'reconnection delay': reconnection_delay 'reconnection delay': reconnection_delay
}); });
@ -468,6 +468,8 @@ var socket,
app.alternatingTitle(''); app.alternatingTitle('');
}); });
templates.setGlobal('relative_path', RELATIVE_PATH);
}); });
showWelcomeMessage = location.href.indexOf('loggedin') !== -1; showWelcomeMessage = location.href.indexOf('loggedin') !== -1;

@ -6,7 +6,9 @@
available_templates = [], available_templates = [],
parsed_variables = {}; parsed_variables = {};
module.exports = templates = {}; module.exports = templates = {
"globals": {}
};
try { try {
fs = require('fs'); fs = require('fs');
@ -242,6 +244,10 @@
parsed_variables[key] = value; parsed_variables[key] = value;
} }
templates.setGlobal = function(key, value) {
templates.globals[key] = value;
}
//modified from https://github.com/psychobunny/dcp.templates //modified from https://github.com/psychobunny/dcp.templates
var parse = function (data) { var parse = function (data) {
var self = this; var self = this;
@ -282,6 +288,13 @@
var template = this.html, var template = this.html,
regex, block; regex, block;
// registering globals
for (var g in templates.globals) {
if (templates.globals.hasOwnProperty(g)) {
data[g] = data[g] || templates.globals[g];
}
}
return (function parse(data, namespace, template, blockInfo) { return (function parse(data, namespace, template, blockInfo) {
if (!data || data.length == 0) { if (!data || data.length == 0) {
template = ''; template = '';

@ -20,7 +20,7 @@ var nconf = require('nconf'),
Admin.isAdmin = function (req, res, next) { Admin.isAdmin = function (req, res, next) {
user.isAdministrator((req.user && req.user.uid) ? req.user.uid : 0, function (err, isAdmin) { user.isAdministrator((req.user && req.user.uid) ? req.user.uid : 0, function (err, isAdmin) {
if (!isAdmin) { if (!isAdmin) {
res.redirect('/403'); res.redirect(403, '/403');
} else { } else {
next(); next();
} }

@ -18,6 +18,7 @@ var path = require('path'),
(function (Api) { (function (Api) {
Api.createRoutes = function (app) { Api.createRoutes = function (app) {
app.namespace('/api', function () { app.namespace('/api', function () {
app.get('/get_templates_listing', function (req, res) { app.get('/get_templates_listing', function (req, res) {
utils.walk(path.join(__dirname, '../../', 'public/templates'), function (err, data) { utils.walk(path.join(__dirname, '../../', 'public/templates'), function (err, data) {

@ -126,6 +126,7 @@
} }
Auth.createRoutes = function(app) { Auth.createRoutes = function(app) {
app.namespace(nconf.get('relative_path'), function () {
app.post('/logout', function(req, res) { app.post('/logout', function(req, res) {
if (req.user && req.user.uid > 0) { if (req.user && req.user.uid > 0) {
winston.info('[Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')'); winston.info('[Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')');
@ -214,5 +215,6 @@
} }
}); });
}); });
});
} }
}(exports)); }(exports));

@ -839,8 +839,8 @@ var path = require('path'),
app[routes[route].method || 'get'](routes[route].route, function(req, res) { app[routes[route].method || 'get'](routes[route].route, function(req, res) {
routes[route].options(req, res, function(options) { routes[route].options(req, res, function(options) {
app.build_header({ app.build_header({
req: options.req, req: options.req || req,
res: options.res res: options.res || res
}, function (err, header) { }, function (err, header) {
res.send(header + options.content + templates.footer); res.send(header + options.content + templates.footer);
}); });

Loading…
Cancel
Save