|
|
|
@ -32,77 +32,86 @@ middleware.isAdmin = function(req, res, next) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
middleware.buildHeader = function(req, res, next) {
|
|
|
|
|
res.locals.renderAdminHeader = true;
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
config: function(next) {
|
|
|
|
|
controllers.api.getConfig(req, res, next);
|
|
|
|
|
},
|
|
|
|
|
footer: function(next) {
|
|
|
|
|
app.render('admin/footer', {}, next);
|
|
|
|
|
}
|
|
|
|
|
}, function(err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.locals.config = results.config;
|
|
|
|
|
res.locals.adminFooter = results.footer;
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
middleware.renderHeader = function(req, res, next) {
|
|
|
|
|
var uid = req.user ? req.user.uid : 0;
|
|
|
|
|
async.parallel([
|
|
|
|
|
function(next) {
|
|
|
|
|
var custom_header = {
|
|
|
|
|
'plugins': [],
|
|
|
|
|
'authentication': []
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
user.getUserFields(uid, ['username', 'userslug', 'email', 'picture', 'email:confirmed'], function(err, userData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userData.uid = uid;
|
|
|
|
|
userData['email:confirmed'] = parseInt(userData['email:confirmed'], 10) === 1;
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
scripts: function(next) {
|
|
|
|
|
plugins.fireHook('filter:admin.scripts.get', [], function(err, scripts) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
var arr = [];
|
|
|
|
|
scripts.forEach(function(script) {
|
|
|
|
|
arr.push({src: nconf.get('url') + script});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
next(null, arr);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
custom_header: function(next) {
|
|
|
|
|
plugins.fireHook('filter:admin.header.build', custom_header, next);
|
|
|
|
|
},
|
|
|
|
|
config: function(next) {
|
|
|
|
|
controllers.api.getConfig(req, res, next);
|
|
|
|
|
}
|
|
|
|
|
}, function(err, results) {
|
|
|
|
|
var custom_header = {
|
|
|
|
|
'plugins': [],
|
|
|
|
|
'authentication': []
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
user.getUserFields(uid, ['username', 'userslug', 'email', 'picture', 'email:confirmed'], function(err, userData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userData.uid = uid;
|
|
|
|
|
userData['email:confirmed'] = parseInt(userData['email:confirmed'], 10) === 1;
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
scripts: function(next) {
|
|
|
|
|
plugins.fireHook('filter:admin.scripts.get', [], function(err, scripts) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
res.locals.config = results.config;
|
|
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
|
relative_path: nconf.get('relative_path'),
|
|
|
|
|
configJSON: JSON.stringify(results.config),
|
|
|
|
|
user: userData,
|
|
|
|
|
userJSON: JSON.stringify(userData),
|
|
|
|
|
plugins: results.custom_header.plugins,
|
|
|
|
|
authentication: results.custom_header.authentication,
|
|
|
|
|
scripts: results.scripts,
|
|
|
|
|
'cache-buster': meta.config['cache-buster'] ? 'v=' + meta.config['cache-buster'] : '',
|
|
|
|
|
env: process.env.NODE_ENV ? true : false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
app.render('admin/header', data, function(err, template) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
res.locals.adminHeader = template;
|
|
|
|
|
next();
|
|
|
|
|
var arr = [];
|
|
|
|
|
scripts.forEach(function(script) {
|
|
|
|
|
arr.push({src: nconf.get('url') + script});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
next(null, arr);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function(next) {
|
|
|
|
|
app.render('admin/footer', {}, function(err, template) {
|
|
|
|
|
res.locals.adminFooter = template;
|
|
|
|
|
next(err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
], next);
|
|
|
|
|
},
|
|
|
|
|
custom_header: function(next) {
|
|
|
|
|
plugins.fireHook('filter:admin.header.build', custom_header, next);
|
|
|
|
|
},
|
|
|
|
|
config: function(next) {
|
|
|
|
|
controllers.api.getConfig(req, res, next);
|
|
|
|
|
}
|
|
|
|
|
}, function(err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
res.locals.config = results.config;
|
|
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
|
relative_path: nconf.get('relative_path'),
|
|
|
|
|
configJSON: JSON.stringify(results.config),
|
|
|
|
|
user: userData,
|
|
|
|
|
userJSON: JSON.stringify(userData),
|
|
|
|
|
plugins: results.custom_header.plugins,
|
|
|
|
|
authentication: results.custom_header.authentication,
|
|
|
|
|
scripts: results.scripts,
|
|
|
|
|
'cache-buster': meta.config['cache-buster'] ? 'v=' + meta.config['cache-buster'] : '',
|
|
|
|
|
env: process.env.NODE_ENV ? true : false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
data.template = {name: res.locals.template};
|
|
|
|
|
data.template[res.locals.template] = true;
|
|
|
|
|
|
|
|
|
|
app.render('admin/header', data, next);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = function(webserver) {
|
|
|
|
|