Skip to content

Node.js based forum software built for the modern web

all users/ pages converted

psychobunnyd072ad60de38
diff --git a/src/controllers/users.js b/src/controllers/users.js
index 5187cf7e20..34fdbf334e 100644
--- a/src/controllers/users.js
+++ b/src/controllers/users.js
@@ -3,5 +3,129 @@ var usersController = {},
posts = require('./../posts');
+usersController.getOnlineUsers = function(req, res, next) {
+ var websockets = require('../socket.io');
+
+ user.getUsers('users:online', 0, 49, function (err, data) {
+ if(err) {
+ return next(err);
+ }
+ var onlineUsers = [];
+
+ uid = 0;
+ if (req.user) {
+ uid = req.user.uid;
+ }
+
+ user.isAdministrator(uid, function (err, isAdministrator) {
+ if(err) {
+ return next(err);
+ }
+
+ if (!isAdministrator) {
+ data = data.filter(function(item) {
+ return item.status !== 'offline';
+ });
+ }
+
+ function iterator(userData, next) {
+ var online = websockets.isUserOnline(userData.uid);
+ if(!online) {
+ db.sortedSetRemove('users:online', userData.uid);
+ return next(null);
+ }
+
+ onlineUsers.push(userData);
+ next(null);
+ }
+
+ var anonymousUserCount = websockets.getOnlineAnonCount();
+
+ async.each(data, iterator, function(err) {
+ var userData = {
+ search_display: 'none',
+ loadmore_display: 'block',
+ users: onlineUsers,
+ anonymousUserCount: anonymousUserCount,
+ show_anon: anonymousUserCount?'':'hide'
+ };
+
+ if (res.locals.isAPI) {
+ res.json(userData);
+ } else {
+ res.render('users', userData);
+ };
+ });
+ });
+ });
+};
+
+usersController.getUsersSortedByPosts = function(req, res, next) {
+ user.getUsers('users:postcount', 0, 49, function (err, data) {
+ var userData = {
+ search_display: 'none',
+ loadmore_display: 'block',
+ users: data,
+ show_anon: 'hide'
+ };
+
+ if (res.locals.isAPI) {
+ res.json(userData);
+ } else {
+ res.render('users', userData);
+ };
+ });
+};
+
+usersController.getUsersSortedByReputation = function(req, res, next) {
+ user.getUsers('users:reputation', 0, 49, function (err, data) {
+ var userData = {
+ search_display: 'none',
+ loadmore_display: 'block',
+ users: data,
+ show_anon: 'hide'
+ };
+
+ if (res.locals.isAPI) {
+ res.json(userData);
+ } else {
+ res.render('users', userData);
+ };
+ });
+};
+
+usersController.getUsersSortedByJoinDate = function(req, res, next) {
+ user.getUsers('users:joindate', 0, 49, function (err, data) {
+ var userData = {
+ search_display: 'none',
+ loadmore_display: 'block',
+ users: data,
+ show_anon: 'hide'
+ };
+
+ if (res.locals.isAPI) {
+ res.json(userData);
+ } else {
+ res.render('users', userData);
+ };
+ });
+};
+
+usersController.getUsersForSearch = function(req, res, next) {
+ var data = {
+ search_display: 'block',
+ loadmore_display: 'none',
+ users: [],
+ show_anon: 'hide'
+ };
+
+ if (res.locals.isAPI) {
+ res.json(data);
+ } else {
+ res.render('users', data);
+ };
+};
+
+
module.exports = usersController;
\ No newline at end of file
diff --git a/src/routes/user.js b/src/routes/user.js
index 1fccb0f47c..5c7edd12a6 100644
--- a/src/routes/user.js
+++ b/src/routes/user.js
@@ -267,96 +267,23 @@ var fs = require('fs'),
}
function getUsersSortedByJoinDate(req, res) {
- user.getUsers('users:joindate', 0, 49, function (err, data) {
- res.json({
- search_display: 'none',
- loadmore_display: 'block',
- users: data,
- show_anon: 'hide'
- });
- });
+
}
function getUsersSortedByPosts(req, res) {
- user.getUsers('users:postcount', 0, 49, function (err, data) {
- res.json({
- search_display: 'none',
- loadmore_display: 'block',
- users: data,
- show_anon: 'hide'
- });
- });
+
}
function getUsersSortedByReputation(req, res) {
- user.getUsers('users:reputation', 0, 49, function (err, data) {
- res.json({
- search_display: 'none',
- loadmore_display: 'block',
- users: data,
- show_anon: 'hide'
- });
- });
+
}
function getOnlineUsers(req, res, next) {
- var websockets = require('../socket.io');
-
- user.getUsers('users:online', 0, 49, function (err, data) {
- if(err) {
- return next(err);
- }
- var onlineUsers = [];
-
- uid = 0;
- if (req.user) {
- uid = req.user.uid;
- }
-
- user.isAdministrator(uid, function (err, isAdministrator) {
- if(err) {
- return next(err);
- }
-
- if (!isAdministrator) {
- data = data.filter(function(item) {
- return item.status !== 'offline';
- });
- }
-
- function iterator(userData, next) {
- var online = websockets.isUserOnline(userData.uid);
- if(!online) {
- db.sortedSetRemove('users:online', userData.uid);
- return next(null);
- }
-
- onlineUsers.push(userData);
- next(null);
- }
-
- var anonymousUserCount = websockets.getOnlineAnonCount();
-
- async.each(data, iterator, function(err) {
- res.json({
- search_display: 'none',
- loadmore_display: 'block',
- users: onlineUsers,
- anonymousUserCount: anonymousUserCount,
- show_anon: anonymousUserCount?'':'hide'
- });
- });
- });
- });
+
}
function getUsersForSearch(req, res) {
- res.json({
- search_display: 'block',
- loadmore_display: 'none',
- users: [],
- show_anon: 'hide'
- });
+
}
function getUserDataByUserSlug(userslug, callerUID, callback) {
diff --git a/src/webserver.js b/src/webserver.js
index ee6b039339..23e1d003ec 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -699,6 +699,25 @@ process.on('uncaughtException', function(err) {
app.get'/user/:userslug/settings', app.buildHeader, app.checkGlobalPrivacySettings, controllers.accounts.accountSettings);
app.get'/api/user/:userslug/settings', app.prepareAPI, app.checkGlobalPrivacySettings controllers.accounts.accountSettings);
+ /* Users */
+ app.get('/users', app.buildHeader, app.checkGlobalPrivacySettings, controllers.users.getOnlineUsers);
+ app.get('/api/users', app.prepareAPI, app.checkGlobalPrivacySettings, controllers.users.getOnlineUsers);
+
+ // was this duped by accident or purpose?
+ app.get('/users/online', app.buildHeader, app.checkGlobalPrivacySettings, controllers.users.getOnlineUsers);
+ app.get('/api/users/online', app.prepareAPI, app.checkGlobalPrivacySettings, controllers.users.getOnlineUsers);
+
+ app.get('/users/sort-posts', app.buildHeader, app.checkGlobalPrivacySettings, controllers.users.getUsersSortedByPosts);
+ app.get('/api/users/sort-posts', app.prepareAPI, app.checkGlobalPrivacySettings, controllers.users.getUsersSortedByPosts);
+
+ app.get('/users/sort-reputation', app.buildHeader, app.checkGlobalPrivacySettings, controllers.users.getUsersSortedByReputation);
+ app.get('/api/users/sort-reputation', app.prepareAPI, app.checkGlobalPrivacySettings, controllers.users.getUsersSortedByReputation);
+
+ app.get('/users/latest', app.buildHeader, app.checkGlobalPrivacySettings, controllers.users.getUsersSortedByJoinDate);
+ app.get('/api/users/latest', app.prepareAPI, app.checkGlobalPrivacySettings, controllers.users.getUsersSortedByJoinDate);
+
+ app.get('/users/search', app.buildHeader, app.checkGlobalPrivacySettings, controllers.users.getUsersForSearch);
+ app.get('/api/users/search', app.prepareAPI, app.checkGlobalPrivacySettings, controllers.users.getUsersForSearch);