Skip to content

Node.js based forum software built for the modern web

adding missing files, re: #4827

Julian Lam5ecbbd228d0f
diff --git a/src/controllers/accounts/info.js b/src/controllers/accounts/info.js
new file mode 100644
index 0000000000..6547db8076
--- /dev/null
+++ b/src/controllers/accounts/info.js
@@ -0,0 +1,28 @@
+'use strict';
+
+var async = require('async'),
+ _ = require('underscore'),
+
+ user = require('../../user'),
+ helpers = require('../helpers'),
+ accountHelpers = require('./helpers');
+
+var infoController = {};
+
+infoController.get = function(req, res, next) {
+ accountHelpers.getBaseUser(req.params.userslug, req.uid, function(err, userData) {
+ async.parallel({
+ ips: async.apply(user.getIPs, res.locals.uid, 4),
+ history: async.apply(user.getModerationHistory, res.locals.uid)
+ }, function(err, data) {
+ data = _.extend(userData, data);
+
+ userData.title = '[[pages:account/info]]';
+ userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: '[[user:settings]]'}]);
+
+ res.render('account/info', data);
+ });
+ });
+};
+
+module.exports = infoController;
\ No newline at end of file
diff --git a/src/user/info.js b/src/user/info.js
new file mode 100644
index 0000000000..a9ca675eab
--- /dev/null
+++ b/src/user/info.js
@@ -0,0 +1,73 @@
+'use strict';
+
+var async = require('async'),
+ _ = require('underscore');
+
+var db = require('../database'),
+ posts = require('../posts'),
+ topics = require('../topics');
+
+module.exports = function(User) {
+ User.getModerationHistory = function(uid, callback) {
+ async.waterfall([
+ function(next) {
+ async.parallel({
+ flags: async.apply(db.getSortedSetRevRangeByScoreWithScores, 'uid:' + uid + ':flag:pids', 0, 20, '+inf', '-inf'),
+ bans: async.apply(db.getSortedSetRevRangeByScoreWithScores, 'uid:' + uid + ':bans', 0, 20, '+inf', '-inf')
+ }, next);
+ },
+ async.apply(getFlagMetadata),
+ async.apply(formatBanData)
+ ], function(err, data) {
+ callback(err, data);
+ });
+ };
+
+ function getFlagMetadata(data, callback) {
+ // Retrieve post title & slug from flags list
+ posts.getPostsFields(data.flags.map(function(flagObj) {
+ return parseInt(flagObj.value, 10);
+ }), ['tid'], function(err, postData) {
+ if (err) {
+ return callback(err);
+ }
+
+ var tids = postData.map(function(post) {
+ return post.tid;
+ });
+
+ topics.getTopicsFields(tids, ['title'], function(err, topicData) {
+ data.flags = data.flags.map(function(flagObj, idx) {
+ flagObj.pid = flagObj.value;
+ flagObj.timestamp = flagObj.score;
+ flagObj.timestampISO = new Date(flagObj.score).toISOString();
+ flagObj.timestampReadable = new Date(flagObj.score).toString();
+
+ delete flagObj.value;
+ delete flagObj.score;
+
+ return _.extend(flagObj, topicData[idx]);
+ });
+
+ callback(null, data);
+ });
+ });
+ }
+
+ function formatBanData(data, callback) {
+ data.bans = data.bans.map(function(banObj) {
+ banObj.until = parseInt(banObj.value, 10);
+ banObj.untilReadable = new Date(banObj.until).toString();
+ banObj.timestamp = parseInt(banObj.score, 10);
+ banObj.timestampReadable = new Date(banObj.score).toString();
+ banObj.timestampISO = new Date(banObj.score).toISOString();
+
+ delete banObj.value;
+ delete banObj.score;
+
+ return banObj;
+ });
+
+ setImmediate(callback, null, data);
+ }
+}
\ No newline at end of file