show username and email history

v1.18.x
Julian Lam 8 years ago
parent 11b5a1f426
commit 172702565e

@ -140,5 +140,7 @@
"info.banned-until": "Banned until %1",
"info.banned-permanently": "Banned permanently",
"info.banned-reason-label": "Reason",
"info.banned-no-reason": "No reason given."
"info.banned-no-reason": "No reason given.",
"info.username-history": "Username History",
"info.email-history": "Email History"
}

@ -21,7 +21,9 @@ infoController.get = function(req, res, callback) {
}
async.parallel({
history: async.apply(user.getModerationHistory, userData.uid),
sessions: async.apply(user.auth.getSessions, userData.uid, req.sessionID)
sessions: async.apply(user.auth.getSessions, userData.uid, req.sessionID),
usernames: async.apply(user.getUsernameHistory, userData.uid),
emails: async.apply(user.getEmailHistory, userData.uid)
}, next);
}
], function(err, data) {
@ -31,6 +33,8 @@ infoController.get = function(req, res, callback) {
userData.history = data.history;
userData.sessions = data.sessions;
userData.usernames = data.usernames;
userData.emails = data.emails;
userData.title = '[[pages:account/info]]';
userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: '[[user:account_info]]'}]);

@ -61,6 +61,30 @@ module.exports = function(User) {
});
};
User.getEmailHistory = function(uid, callback) {
db.getSortedSetRevRangeWithScores('user:' + uid + ':emails', 0, -1, function(err, data) {
callback(err, data.map(function(set) {
set.timestamp = set.score;
set.timestampISO = new Date(set.score).toISOString();
set.value = set.value.split(':')[0];
delete set.score;
return set;
}));
});
};
User.getUsernameHistory = function(uid, callback) {
db.getSortedSetRevRangeWithScores('user:' + uid + ':usernames', 0, -1, function(err, data) {
callback(err, data.map(function(set) {
set.timestamp = set.score;
set.timestampISO = new Date(set.score).toISOString();
set.value = set.value.split(':')[0];
delete set.score;
return set;
}));
});
};
function getFlagMetadata(data, callback) {
var pids = data.flags.map(function(flagObj) {
return parseInt(flagObj.value, 10);

@ -178,6 +178,7 @@ module.exports = function(User) {
function(next) {
db.sortedSetAdd('email:uid', uid, newEmail.toLowerCase(), next);
},
async.apply(db.sortedSetAdd, 'user:' + uid + ':emails', Date.now(), newEmail + ':' + Date.now()),
function(next) {
db.sortedSetAdd('email:sorted', 0, newEmail.toLowerCase() + ':' + uid, next);
},
@ -219,7 +220,8 @@ module.exports = function(User) {
function(next) {
async.series([
async.apply(db.sortedSetRemove, 'username:sorted', userData.username.toLowerCase() + ':' + uid),
async.apply(db.sortedSetAdd, 'username:sorted', 0, newUsername.toLowerCase() + ':' + uid)
async.apply(db.sortedSetAdd, 'username:sorted', 0, newUsername.toLowerCase() + ':' + uid),
async.apply(db.sortedSetAdd, 'user:' + uid + ':usernames', Date.now(), newUsername + ':' + Date.now())
], next);
},
], callback);

Loading…
Cancel
Save