|
|
|
@ -22,7 +22,6 @@ var nconf = require('nconf'),
|
|
|
|
|
utils = require('./../../public/src/utils'),
|
|
|
|
|
templates = require('./../../public/src/templates');
|
|
|
|
|
|
|
|
|
|
var Admin = {};
|
|
|
|
|
|
|
|
|
|
function uploadImage(filename, req, res) {
|
|
|
|
|
function done(err, image) {
|
|
|
|
@ -45,69 +44,7 @@ function uploadImage(filename, req, res) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = function(app, middleware, controllers) {
|
|
|
|
|
app.all('/api/admin/*', middleware.admin.isAdmin, middleware.prepareAPI);
|
|
|
|
|
app.all('/admin/*', middleware.admin.isAdmin);
|
|
|
|
|
app.get('/admin', middleware.admin.isAdmin);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.get('/admin/', middleware.admin.buildHeader, controllers.admin.home);
|
|
|
|
|
app.get('/api/admin/index', controllers.admin.home);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/users/search', middleware.admin.buildHeader, controllers.admin.users.search);
|
|
|
|
|
app.get('/api/admin/users/search', controllers.admin.users.search);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/users/latest', middleware.admin.buildHeader, controllers.admin.users.latest);
|
|
|
|
|
app.get('/api/admin/users/latest', controllers.admin.users.latest);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/users/sort-posts', middleware.admin.buildHeader, controllers.admin.users.sortByPosts);
|
|
|
|
|
app.get('/api/admin/users/sort-posts', controllers.admin.users.sortByPosts);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/users/sort-reputation', middleware.admin.buildHeader, controllers.admin.users.sortByReputation);
|
|
|
|
|
app.get('/api/admin/users/sort-reputation', controllers.admin.users.sortByReputation);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/users', middleware.admin.buildHeader, controllers.admin.users.sortByJoinDate);
|
|
|
|
|
app.get('/api/admin/users', controllers.admin.users.sortByJoinDate);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/categories/active', middleware.admin.buildHeader, controllers.admin.categories.active);
|
|
|
|
|
app.get('/api/admin/categories/active', controllers.admin.categories.active);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/categories/disabled', middleware.admin.buildHeader, controllers.admin.categories.disabled);
|
|
|
|
|
app.get('/api/admin/categories/disabled', controllers.admin.categories.disabled);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/topics', middleware.admin.buildHeader, controllers.admin.topics.get);
|
|
|
|
|
app.get('/api/admin/topics', controllers.admin.topics.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/database', middleware.admin.buildHeader, controllers.admin.database.get);
|
|
|
|
|
app.get('/api/admin/database', controllers.admin.database.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/events', middleware.admin.buildHeader, controllers.admin.events.get);
|
|
|
|
|
app.get('/api/admin/events', controllers.admin.events.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/plugins', middleware.admin.buildHeader, controllers.admin.plugins.get);
|
|
|
|
|
app.get('/api/admin/plugins', controllers.admin.plugins.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/languages', middleware.admin.buildHeader, controllers.admin.languages.get);
|
|
|
|
|
app.get('/api/admin/languages', controllers.admin.languages.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/settings', middleware.admin.buildHeader, controllers.admin.settings.get);
|
|
|
|
|
app.get('/api/admin/settings', controllers.admin.settings.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/logger', middleware.admin.buildHeader, controllers.admin.logger.get);
|
|
|
|
|
app.get('/api/admin/logger', controllers.admin.logger.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/themes', middleware.admin.buildHeader, controllers.admin.themes.get);
|
|
|
|
|
app.get('/api/admin/themes', controllers.admin.themes.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/groups', middleware.admin.buildHeader, controllers.admin.groups.get);
|
|
|
|
|
app.get('/api/admin/groups', controllers.admin.groups.get);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.namespace('/admin', function () {
|
|
|
|
|
app.post('/category/uploadpicture', function(req, res) {
|
|
|
|
|
function uploadCategoryPicture(req, res, next) {
|
|
|
|
|
if (!req.user) {
|
|
|
|
|
return res.redirect('/403');
|
|
|
|
|
}
|
|
|
|
@ -134,9 +71,9 @@ module.exports = function(app, middleware, controllers) {
|
|
|
|
|
var filename = 'category-' + params.cid + path.extname(req.files.userPhoto.name);
|
|
|
|
|
|
|
|
|
|
uploadImage(filename, req, res);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.post('/uploadfavicon', function(req, res) {
|
|
|
|
|
function uploadFavicon(req, res, next) {
|
|
|
|
|
if (!req.user) {
|
|
|
|
|
return res.redirect('/403');
|
|
|
|
|
}
|
|
|
|
@ -161,10 +98,9 @@ module.exports = function(app, middleware, controllers) {
|
|
|
|
|
var rs = {path: image.url};
|
|
|
|
|
res.send(req.xhr ? rs : JSON.stringify(rs));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.post('/uploadlogo', function(req, res) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function uploadLogo(req, res, next) {
|
|
|
|
|
if (!req.user) {
|
|
|
|
|
return res.redirect('/403');
|
|
|
|
|
}
|
|
|
|
@ -181,52 +117,80 @@ module.exports = function(app, middleware, controllers) {
|
|
|
|
|
var filename = 'site-logo' + path.extname(req.files.userPhoto.name);
|
|
|
|
|
|
|
|
|
|
uploadImage(filename, req, res);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.get('/users/csv', function(req, res) {
|
|
|
|
|
function getUsersCSV(req, res, next) {
|
|
|
|
|
user.getUsersCSV(function(err, data) {
|
|
|
|
|
res.attachment('users.csv');
|
|
|
|
|
res.setHeader('Content-Type', 'text/csv');
|
|
|
|
|
res.end(data);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var custom_routes = {
|
|
|
|
|
'routes': [],
|
|
|
|
|
'api': []
|
|
|
|
|
};
|
|
|
|
|
module.exports = function(app, middleware, controllers) {
|
|
|
|
|
app.all('/api/admin/*', middleware.admin.isAdmin, middleware.prepareAPI);
|
|
|
|
|
app.all('/admin/*', middleware.admin.isAdmin);
|
|
|
|
|
app.get('/admin', middleware.admin.isAdmin);
|
|
|
|
|
|
|
|
|
|
plugins.ready(function() {
|
|
|
|
|
plugins.fireHook('filter:admin.create_routes', custom_routes, function(err, custom_routes) {
|
|
|
|
|
var route, routes = custom_routes.routes;
|
|
|
|
|
|
|
|
|
|
for (route in routes) {
|
|
|
|
|
if (routes.hasOwnProperty(route)) {
|
|
|
|
|
(function(route) {
|
|
|
|
|
app[routes[route].method || 'get']('/admin' + routes[route].route, function(req, res) {
|
|
|
|
|
routes[route].options(req, res, function(options) {
|
|
|
|
|
Admin.buildHeader(req, res, function (err, header) {
|
|
|
|
|
res.send(header + options.content + templates['admin/footer']);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}(route));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var apiRoutes = custom_routes.api;
|
|
|
|
|
for (route in apiRoutes) {
|
|
|
|
|
if (apiRoutes.hasOwnProperty(route)) {
|
|
|
|
|
(function(route) {
|
|
|
|
|
app[apiRoutes[route].method || 'get']('/api/admin' + apiRoutes[route].route, function(req, res) {
|
|
|
|
|
apiRoutes[route].callback(req, res, function(data) {
|
|
|
|
|
res.json(data);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}(route));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get('/admin/', middleware.admin.buildHeader, controllers.admin.home);
|
|
|
|
|
app.get('/api/admin/index', controllers.admin.home);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/users/search', middleware.admin.buildHeader, controllers.admin.users.search);
|
|
|
|
|
app.get('/api/admin/users/search', controllers.admin.users.search);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/users/latest', middleware.admin.buildHeader, controllers.admin.users.latest);
|
|
|
|
|
app.get('/api/admin/users/latest', controllers.admin.users.latest);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/users/sort-posts', middleware.admin.buildHeader, controllers.admin.users.sortByPosts);
|
|
|
|
|
app.get('/api/admin/users/sort-posts', controllers.admin.users.sortByPosts);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/users/sort-reputation', middleware.admin.buildHeader, controllers.admin.users.sortByReputation);
|
|
|
|
|
app.get('/api/admin/users/sort-reputation', controllers.admin.users.sortByReputation);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/users', middleware.admin.buildHeader, controllers.admin.users.sortByJoinDate);
|
|
|
|
|
app.get('/api/admin/users', controllers.admin.users.sortByJoinDate);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/categories/active', middleware.admin.buildHeader, controllers.admin.categories.active);
|
|
|
|
|
app.get('/api/admin/categories/active', controllers.admin.categories.active);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/categories/disabled', middleware.admin.buildHeader, controllers.admin.categories.disabled);
|
|
|
|
|
app.get('/api/admin/categories/disabled', controllers.admin.categories.disabled);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/topics', middleware.admin.buildHeader, controllers.admin.topics.get);
|
|
|
|
|
app.get('/api/admin/topics', controllers.admin.topics.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/database', middleware.admin.buildHeader, controllers.admin.database.get);
|
|
|
|
|
app.get('/api/admin/database', controllers.admin.database.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/events', middleware.admin.buildHeader, controllers.admin.events.get);
|
|
|
|
|
app.get('/api/admin/events', controllers.admin.events.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/plugins', middleware.admin.buildHeader, controllers.admin.plugins.get);
|
|
|
|
|
app.get('/api/admin/plugins', controllers.admin.plugins.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/languages', middleware.admin.buildHeader, controllers.admin.languages.get);
|
|
|
|
|
app.get('/api/admin/languages', controllers.admin.languages.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/settings', middleware.admin.buildHeader, controllers.admin.settings.get);
|
|
|
|
|
app.get('/api/admin/settings', controllers.admin.settings.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/logger', middleware.admin.buildHeader, controllers.admin.logger.get);
|
|
|
|
|
app.get('/api/admin/logger', controllers.admin.logger.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/themes', middleware.admin.buildHeader, controllers.admin.themes.get);
|
|
|
|
|
app.get('/api/admin/themes', controllers.admin.themes.get);
|
|
|
|
|
|
|
|
|
|
app.get('/admin/groups', middleware.admin.buildHeader, controllers.admin.groups.get);
|
|
|
|
|
app.get('/api/admin/groups', controllers.admin.groups.get);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.namespace('/admin', function () {
|
|
|
|
|
app.get('/users/csv', getUsersCSV);
|
|
|
|
|
|
|
|
|
|
app.post('/category/uploadpicture', uploadCategoryPicture);
|
|
|
|
|
app.post('/uploadfavicon', uploadFavicon);
|
|
|
|
|
app.post('/uploadlogo', uploadLogo);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|