From cc8ac2c0266c062378b8f2fc35f96ab646037735 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Tue, 25 Feb 2014 17:21:30 -0500 Subject: [PATCH] get ips if admin or self --- src/routes/authentication.js | 2 ++ src/routes/user.js | 15 ++++++++++++--- src/user.js | 4 ++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/routes/authentication.js b/src/routes/authentication.js index f72836caf2..bde803208b 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -105,7 +105,9 @@ req.login({ uid: userData.uid }, function() { + console.log('TESTING', userData.uid); if (userData.uid) { + console.log('FAIL?', userData.uid); user.logIP(userData.uid, req.ip); } diff --git a/src/routes/user.js b/src/routes/user.js index 45a0c7f20c..47434e5bf0 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -230,6 +230,7 @@ var fs = require('fs'), app.get('/api/user/:userslug/posts', isAllowed, getUserPosts); app.get('/api/user/uid/:uid', isAllowed, getUserData); app.get('/api/user/:userslug', isAllowed, getUserProfile); + app.get('/api/users', isAllowed, getOnlineUsers); app.get('/api/users/sort-posts', isAllowed, getUsersSortedByPosts); app.get('/api/users/sort-reputation', isAllowed, getUsersSortedByReputation); @@ -590,6 +591,9 @@ var fs = require('fs'), }, followStats: function(next) { user.getFollowStats(uid, next); + }, + ips: function(next) { + user.getIPs(uid, next); } }, function(err, results) { if(err || !results.userData) { @@ -599,6 +603,7 @@ var fs = require('fs'), var userData = results.userData; var userSettings = results.userSettings; var isAdmin = results.isAdmin; + var self = parseInt(callerUID, 10) === parseInt(userData.uid, 10); userData.joindate = utils.toISOString(userData.joindate); if(userData.lastonline) { @@ -614,19 +619,23 @@ var fs = require('fs'), } function canSeeEmail() { - return isAdmin || parseInt(callerUID, 10) === parseInt(userData.uid, 10) || (userData.email && userSettings.showemail); + return ; } - if (!canSeeEmail()) { + if (!(isAdmin || self || (userData.email && userSettings.showemail))) { userData.email = ""; } - if (parseInt(callerUID, 10) === parseInt(userData.uid, 10) && !userSettings.showemail) { + if (self && !userSettings.showemail) { userData.emailClass = ""; } else { userData.emailClass = "hide"; } + if (isAdmin || self) { + userData.ips = results.ips; + } + userData.websiteName = userData.website.replace('http://', '').replace('https://', ''); userData.banned = parseInt(userData.banned, 10) === 1; userData.uid = userData.uid; diff --git a/src/user.js b/src/user.js index ac48c4e7f0..9e8e4f7f49 100644 --- a/src/user.js +++ b/src/user.js @@ -968,6 +968,10 @@ var bcrypt = require('bcryptjs'), db.sortedSetAdd('uid:' + uid + ':ip', +new Date(), ip || 'Unknown'); }; + User.getIPs = function(uid, callback) { + db.getSortedSetRevRange('uid:' + uid + ':ip', 0, 5, callback); + }; + User.email = { verify: function(uid, email) { if (!plugins.hasListeners('action:email.send')) {