From cc8ac2c0266c062378b8f2fc35f96ab646037735 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Tue, 25 Feb 2014 17:21:30 -0500 Subject: [PATCH 1/3] 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')) { From de3bc84fde76e2c52296147a6fc226091dd9c5bc Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Tue, 25 Feb 2014 17:23:13 -0500 Subject: [PATCH 2/3] removed logs --- src/routes/authentication.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/routes/authentication.js b/src/routes/authentication.js index bde803208b..f72836caf2 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -105,9 +105,7 @@ 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); } From 1ba3acfd032aa149c754ac6834d3e2675d2d3561 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Tue, 25 Feb 2014 17:34:42 -0500 Subject: [PATCH 3/3] display ips to admins/users on profile --- public/language/en_GB/global.json | 1 + public/templates/account.tpl | 12 ++++++++++++ src/routes/user.js | 2 +- src/user.js | 12 ++++++++++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/public/language/en_GB/global.json b/public/language/en_GB/global.json index b1dff9ec46..b41f69b915 100644 --- a/public/language/en_GB/global.json +++ b/public/language/en_GB/global.json @@ -65,6 +65,7 @@ "in": "in", "recentposts": "Recent Posts", + "recentips": "Recently Logged In IPs", "online": "Online", "away": "Away", diff --git a/public/templates/account.tpl b/public/templates/account.tpl index dac12502d9..d099d68767 100644 --- a/public/templates/account.tpl +++ b/public/templates/account.tpl @@ -108,6 +108,18 @@ + +
+
+

[[global:recentips]]

+
+
+ + {ips.ip} + +
+
+ diff --git a/src/routes/user.js b/src/routes/user.js index 47434e5bf0..136473ce1b 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -593,7 +593,7 @@ var fs = require('fs'), user.getFollowStats(uid, next); }, ips: function(next) { - user.getIPs(uid, next); + user.getIPs(uid, 4, next); } }, function(err, results) { if(err || !results.userData) { diff --git a/src/user.js b/src/user.js index 9e8e4f7f49..ae14774e82 100644 --- a/src/user.js +++ b/src/user.js @@ -968,8 +968,16 @@ 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.getIPs = function(uid, end, callback) { + db.getSortedSetRevRange('uid:' + uid + ':ip', 0, end, function(err, ips) { + if(err) { + return callback(err); + } + + callback(null, ips.map(function(ip) { + return {ip:ip}; + })); + }); }; User.email = {