diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js index e69391a198..80bf88baa9 100644 --- a/src/controllers/accounts.js +++ b/src/controllers/accounts.js @@ -18,27 +18,15 @@ var fs = require('fs'), file = require('./../file'); function userNotFound(res) { - if (res.locals.isAPI) { - return res.json(404, { - error: 'User not found!' - }); - } else { - return res.render('404', { - error: 'User not found!' - }); - } + return res.render('404', { + error: 'User not found!' + }); } function userNotAllowed(res) { - if (res.locals.isAPI) { - return res.json(403, { - error: 'Not allowed.' - }); - } else { - return res.render('403', { - error: 'Not allowed.' - }); - } + return res.render('403', { + error: 'Not allowed.' + }); } function getUserDataByUserSlug(userslug, callerUID, callback) { @@ -165,11 +153,7 @@ accountsController.getAccount = function(req, res, next) { postTools.parse(userData.signature, function (err, signature) { userData.signature = signature; - if (res.locals.isAPI) { - res.json(userData); - } else { - res.render('account', userData); - } + res.render('account', userData); }); }); }); @@ -192,11 +176,7 @@ accountsController.getFollowing = function(req, res, next) { userData.following = followingData; userData.followingCount = followingData.length; - if (res.locals.isAPI) { - res.json(userData); - } else { - res.render('following', userData); - } + res.render('following', userData); }); } else { @@ -221,11 +201,7 @@ accountsController.getFollowers = function(req, res, next) { userData.followers = followersData; userData.followersCount = followersData.length; - if (res.locals.isAPI) { - res.json(userData); - } else { - res.render('followers', userData); - } + res.render('followers', userData); }); } else { return userNotFound(); @@ -264,11 +240,7 @@ accountsController.getFavourites = function(req, res, next) { userData.posts = favourites.posts; userData.nextStart = favourites.nextStart; - if (res.locals.isAPI) { - res.json(userData); - } else { - res.render('favourites', userData); - } + res.render('favourites', userData); }); }); }); @@ -301,11 +273,7 @@ accountsController.getPosts = function(req, res, next) { userData.posts = userPosts.posts; userData.nextStart = userPosts.nextStart; - if (res.locals.isAPI) { - res.json(userData); - } else { - res.render('accountposts', userData); - } + res.render('accountposts', userData); }); }); }); @@ -319,11 +287,7 @@ accountsController.accountEdit = function(req, res, next) { return next(err); } - if (res.locals.isAPI) { - res.json(userData); - } else { - res.render('accountedit', userData); - } + res.render('accountedit', userData); }); }; @@ -360,11 +324,7 @@ accountsController.accountSettings = function(req, res, next) { userData.theirid = uid; userData.settings = settings; - if (res.locals.isAPI) { - res.json(userData); - } else { - res.render('accountsettings', userData); - } + res.render('accountsettings', userData); }); }); @@ -475,15 +435,9 @@ accountsController.uploadPicture = function (req, res, next) { accountsController.getNotifications = function(req, res, next) { user.notifications.getAll(req.user.uid, null, null, function(err, notifications) { - if (res.locals.isAPI) { - res.json({ - notifications: notifications - }); - } else { - res.render('notifications', { - notifications: notifications - }); - } + res.render('notifications', { + notifications: notifications + }); }); }; diff --git a/src/controllers/admin.js b/src/controllers/admin.js index 0352c9d01f..7882cb1118 100644 --- a/src/controllers/admin.js +++ b/src/controllers/admin.js @@ -28,97 +28,61 @@ var adminController = { }; adminController.home = function(req, res, next) { - var data = { + res.render('admin/index', { version: pkg.version, emailerInstalled: plugins.hasListeners('action:email.send'), searchInstalled: plugins.hasListeners('filter:search.query') - }; - - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('admin/index', data); - } + }); }; adminController.users.search = function(req, res, next) { - var data = { + res.render('admin/users', { search_display: 'block', loadmore_display: 'none', users: [] - }; - - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('admin/users', data); - } + }); }; adminController.users.latest = function(req, res, next) { user.getUsers('users:joindate', 0, 49, function(err, users) { - var data = { + res.render('admin/users', { search_display: 'none', loadmore_display: 'block', users: users, yourid: req.user.uid - }; - - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('admin/users', data); - } + }); }); }; adminController.users.sortByPosts = function(req, res, next) { user.getUsers('users:postcount', 0, 49, function(err, users) { - var data = { + res.render('admin/users', { search_display: 'none', loadmore_display: 'block', users: users, yourid: req.user.uid - }; - - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('admin/users', data); - } + }); }); }; adminController.users.sortByReputation = function(req, res, next) { user.getUsers('users:reputation', 0, 49, function(err, users) { - var data = { + res.render('admin/users', { search_display: 'none', loadmore_display: 'block', users: users, yourid: req.user.uid - }; - - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('admin/users', data); - } + }); }); }; adminController.users.sortByJoinDate = function(req, res, next) { user.getUsers('users:joindate', 0, 49, function(err, users) { - var data = { + res.render('admin/users', { search_display: 'none', users: users, yourid: req.user.uid - }; - - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('admin/users', data); - } + }); }); }; @@ -127,11 +91,8 @@ adminController.categories.active = function(req, res, next) { data.categories = data.categories.filter(function (category) { return !category.disabled; }); - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('admin/categories', data); - } + + res.render('admin/categories', data); }); }; @@ -141,37 +102,23 @@ adminController.categories.disabled = function(req, res, next) { return category.disabled; }); - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('admin/categories', data); - } + res.render('admin/categories', data); }); }; adminController.database.get = function(req, res, next) { db.info(function (err, data) { - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('admin/database', data); - } + res.render('admin/database', data); }); }; // todo: deprecate this seemingly useless view adminController.topics.get = function(req, res, next) { topics.getAllTopics(0, 19, function (err, topics) { - var data = { + res.render('admin/topics', { topics: topics, notopics: topics.length === 0 - }; - - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('admin/topics', data); - } + }); }); }; @@ -182,12 +129,9 @@ adminController.events.get = function(req, res, next) { } data = data.toString().split('\n').reverse().join('\n'); - - if (res.locals.isAPI) { - res.json({eventdata: data}); - } else { - res.render('admin/events', {eventdata: data}); - } + res.render('admin/events', { + eventdata: data + }); }); }; @@ -197,38 +141,26 @@ adminController.plugins.get = function(req, res, next) { plugins = []; } - if (res.locals.isAPI) { - res.json({plugins: plugins}); - } else { - res.render('admin/plugins', {plugins: plugins}); - } + res.render('admin/plugins', { + plugins: plugins + }); }); }; adminController.languages.get = function(req, res, next) { languages.list(function(err, languages) { - if (res.locals.isAPI) { - res.json({languages: languages}); - } else { - res.render('admin/languages', {languages: languages}); - } + res.render('admin/languages', { + languages: languages + }); }); }; adminController.settings.get = function(req, res, next) { - if (res.locals.isAPI) { - res.json({}); - } else { - res.render('admin/settings', {}); - } + res.render('admin/settings', {}); }; adminController.logger.get = function(req, res, next) { - if (res.locals.isAPI) { - res.json({}); - } else { - res.render('admin/logger', {}); - } + res.render('admin/logger', {}); }; adminController.themes.get = function(req, res, next) { @@ -252,16 +184,10 @@ adminController.themes.get = function(req, res, next) { } } - var data = { + res.render('admin/themes', { areas: widgetData.areas, widgets: widgetData.widgets - }; - - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('admin/themes', data); - } + }); }); }); }; @@ -279,17 +205,12 @@ adminController.groups.get = function(req, res, next) { }, next); } ], function(err, groupData) { - var groups = groupData[0].concat(groupData[1]), - data = { - groups: groups, - yourid: req.user.uid - }; + var groups = groupData[0].concat(groupData[1]); - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('admin/groups', data); - } + res.render('admin/groups', { + groups: groups, + yourid: req.user.uid + }); }); }; diff --git a/src/controllers/categories.js b/src/controllers/categories.js index 798e246297..6deb506fcc 100644 --- a/src/controllers/categories.js +++ b/src/controllers/categories.js @@ -16,11 +16,7 @@ categoriesController.recent = function(req, res, next) { return next(err); } - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('recent', data); - } + res.render('recent', data); }); }; @@ -36,11 +32,7 @@ categoriesController.popular = function(req, res, next) { return next(err); } - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('popular', data); - } + res.render('popular', data); }); }; @@ -52,11 +44,7 @@ categoriesController.unread = function(req, res, next) { return next(err); } - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('unread', data); - } + res.render('unread', data); }); }; @@ -68,11 +56,7 @@ categoriesController.unreadTotal = function(req, res, next) { return next(err); } - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('unread', data); - } + res.render('unread', data); }); }; @@ -182,11 +166,7 @@ categoriesController.get = function(req, res, next) { }); } - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('category', data); - } + res.render('category', data); }); }; diff --git a/src/controllers/index.js b/src/controllers/index.js index f691204aa7..a40c6c4626 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -85,32 +85,20 @@ Controllers.home = function(req, res, next) { }; Controllers.search = function(req, res, next) { - var data = { + res.render('search', { show_no_topics: 'hide', show_no_posts: 'hide', show_results: 'hide', search_query: '', posts: [], topics: [] - }; - - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('search', data); - } + }); }; Controllers.reset = function(req, res, next) { - var data = { + res.render('reset', { reset_code: req.params.code ? req.params.code : null - }; - - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('reset', data); - } + }); }; Controllers.login = function(req, res, next) { @@ -135,11 +123,7 @@ Controllers.login = function(req, res, next) { data.token = res.locals.csrf_token; data.showResetLink = emailersPresent; - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('login', data); - } + res.render('login', data); }; Controllers.register = function(req, res, next) { @@ -167,11 +151,7 @@ Controllers.register = function(req, res, next) { data.minimumPasswordLength = meta.config.minimumPasswordLength; data.termsOfUse = meta.config.termsOfUse; - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('register', data); - } + res.render('register', data); }; @@ -191,11 +171,7 @@ Controllers.confirmEmail = function(req, res, next) { }; } - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('confirm', data); - } + res.render('confirm', data); }); }; @@ -228,11 +204,7 @@ Controllers.outgoing = function(req, res, next) { }; if (url) { - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('outgoing', data); - } + res.render('outgoing', data); } else { res.status(404); res.redirect(nconf.get('relative_path') + '/404'); diff --git a/src/controllers/static.js b/src/controllers/static.js index bde9c10360..0fa71f12a7 100644 --- a/src/controllers/static.js +++ b/src/controllers/static.js @@ -3,27 +3,15 @@ var staticController = {}; staticController['404'] = function(req, res, next) { - if (res.locals.isAPI) { - res.json({}); - } else { - res.render('404', {}); - } + res.render('404', {}); }; staticController['403'] = function(req, res, next) { - if (res.locals.isAPI) { - res.json({}); - } else { - res.render('403', {}); - } + res.render('403', {}); }; staticController['500'] = function(req, res, next) { - if (res.locals.isAPI) { - res.json({}); - } else { - res.render('500', {}); - } + res.render('500', {}); }; module.exports = staticController; \ No newline at end of file diff --git a/src/controllers/topics.js b/src/controllers/topics.js index 143188bd2e..f71e751627 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -168,11 +168,7 @@ topicsController.get = function(req, res, next) { }); } - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('topic', data); - } + res.render('topic', data); }); }; diff --git a/src/controllers/users.js b/src/controllers/users.js index 7c216dc5f0..49a61b81cb 100644 --- a/src/controllers/users.js +++ b/src/controllers/users.js @@ -53,11 +53,7 @@ usersController.getOnlineUsers = function(req, res, next) { show_anon: anonymousUserCount?'':'hide' }; - if (res.locals.isAPI) { - res.json(userData); - } else { - res.render('users', userData); - } + res.render('users', userData); }); }); }); @@ -72,11 +68,7 @@ usersController.getUsersSortedByPosts = function(req, res, next) { show_anon: 'hide' }; - if (res.locals.isAPI) { - res.json(userData); - } else { - res.render('users', userData); - } + res.render('users', userData); }); }; @@ -89,11 +81,7 @@ usersController.getUsersSortedByReputation = function(req, res, next) { show_anon: 'hide' }; - if (res.locals.isAPI) { - res.json(userData); - } else { - res.render('users', userData); - } + res.render('users', userData); }); }; @@ -106,11 +94,7 @@ usersController.getUsersSortedByJoinDate = function(req, res, next) { show_anon: 'hide' }; - if (res.locals.isAPI) { - res.json(userData); - } else { - res.render('users', userData); - } + res.render('users', userData); }); }; @@ -122,11 +106,7 @@ usersController.getUsersForSearch = function(req, res, next) { show_anon: 'hide' }; - if (res.locals.isAPI) { - res.json(data); - } else { - res.render('users', data); - } + res.render('users', data); };