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 45a0c7f20c..136473ce1b 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, 4, 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..ae14774e82 100644 --- a/src/user.js +++ b/src/user.js @@ -968,6 +968,18 @@ var bcrypt = require('bcryptjs'), db.sortedSetAdd('uid:' + uid + ':ip', +new Date(), ip || 'Unknown'); }; + 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 = { verify: function(uid, email) { if (!plugins.hasListeners('action:email.send')) {