Merge branch 'master' into develop

This commit is contained in:
Julian Lam
2017-02-24 12:46:40 -05:00
449 changed files with 9202 additions and 6984 deletions

View File

@@ -9,7 +9,6 @@ var winston = require('winston');
var flags = require('../flags');
module.exports = function (User) {
User.logIP = function (uid, ip) {
var now = Date.now();
db.sortedSetAdd('uid:' + uid + ':ip', now, ip || 'Unknown');
@@ -40,7 +39,7 @@ module.exports = function (User) {
uids = users.map(function (user) {
return user.score;
});
plugins.fireHook('filter:user.csvFields', {fields: ['uid', 'email', 'username']}, next);
plugins.fireHook('filter:user.csvFields', { fields: ['uid', 'email', 'username'] }, next);
},
function (data, next) {
User.getUsersFields(uids, data.fields, next);
@@ -53,7 +52,7 @@ module.exports = function (User) {
});
next(null, csvContent);
}
},
], callback);
};
};

View File

@@ -14,7 +14,6 @@ var utils = require('../../public/src/utils');
var plugins = require('../plugins');
module.exports = function (User) {
User.addToApprovalQueue = function (userData, callback) {
userData.userslug = utils.slugify(userData.username);
async.waterfall([
@@ -29,9 +28,9 @@ module.exports = function (User) {
username: userData.username,
email: userData.email,
ip: userData.ip,
hashedPassword: hashedPassword
hashedPassword: hashedPassword,
};
plugins.fireHook('filter:user.addToApprovalQueue', {data: data, userData: userData}, next);
plugins.fireHook('filter:user.addToApprovalQueue', { data: data, userData: userData }, next);
},
function (results, next) {
db.setObject('registration:queue:name:' + userData.username, results.data, next);
@@ -41,7 +40,7 @@ module.exports = function (User) {
},
function (next) {
sendNotificationToAdmins(userData.username, next);
}
},
], callback);
};
@@ -52,12 +51,12 @@ module.exports = function (User) {
bodyShort: '[[notifications:new_register, ' + username + ']]',
nid: 'new_register:' + username,
path: '/admin/manage/registration',
mergeId: 'new_register'
mergeId: 'new_register',
}, next);
},
function (notification, next) {
notifications.pushGroup(notification, 'administrators', next);
}
},
], callback);
}
@@ -93,7 +92,7 @@ module.exports = function (User) {
username: username,
subject: subject,
template: 'registration_accepted',
uid: uid
uid: uid,
};
emailer.send('registration_accepted', uid, data, next);
@@ -101,7 +100,7 @@ module.exports = function (User) {
},
function (next) {
next(null, uid);
}
},
], callback);
};
@@ -115,7 +114,7 @@ module.exports = function (User) {
async.each(uids, function (uid, next) {
notifications.markRead(nid, uid, next);
}, next);
}
},
], callback);
}
@@ -126,14 +125,14 @@ module.exports = function (User) {
},
function (next) {
markNotificationRead(username, next);
}
},
], callback);
};
function removeFromQueue(username, callback) {
async.parallel([
async.apply(db.sortedSetRemove, 'registration:queue', username),
async.apply(db.delete, 'registration:queue:name:' + username)
async.apply(db.delete, 'registration:queue:name:' + username),
], function (err) {
callback(err);
});
@@ -191,7 +190,7 @@ module.exports = function (User) {
'&email=' + encodeURIComponent(user.email) +
'&username=' + encodeURIComponent(user.username) +
'&f=json',
json: true
json: true,
}, function (err, response, body) {
if (err) {
return next();
@@ -205,20 +204,18 @@ module.exports = function (User) {
next();
});
}
},
], function (err) {
next(err, user);
});
}, next);
},
function (users, next) {
plugins.fireHook('filter:user.getRegistrationQueue', {users: users}, next);
plugins.fireHook('filter:user.getRegistrationQueue', { users: users }, next);
},
function (results, next) {
next(null, results.users);
}
},
], callback);
};
};

View File

@@ -37,10 +37,10 @@ module.exports = function (User) {
events.log({
type: 'account-locked',
uid: uid,
ip: ip
ip: ip,
});
next(new Error('[[error:account-locked]]'));
}
},
], callback);
};
@@ -51,7 +51,7 @@ module.exports = function (User) {
User.auth.resetLockout = function (uid, callback) {
async.parallel([
async.apply(db.delete, 'loginAttempts:' + uid),
async.apply(db.delete, 'lockout:' + uid)
async.apply(db.delete, 'lockout:' + uid),
], callback);
};
@@ -78,8 +78,8 @@ module.exports = function (User) {
});
// Revoke any sessions that have expired, return filtered list
var expiredSids = [],
expired;
var expiredSids = [];
var expired;
sessions = sessions.filter(function (sessionObj, idx) {
expired = !sessionObj || !sessionObj.hasOwnProperty('passport') ||
@@ -98,7 +98,7 @@ module.exports = function (User) {
}, function (err) {
next(err, sessions);
});
}
},
], function (err, sessions) {
callback(err, sessions ? sessions.map(function (sessObj) {
sessObj.meta.datetimeISO = new Date(sessObj.meta.datetime).toISOString();
@@ -128,7 +128,7 @@ module.exports = function (User) {
}
},
async.apply(db.sortedSetRemove, 'uid:' + uid + ':sessions', sessionId),
async.apply(db.sessionStore.destroy.bind(db.sessionStore), sessionId)
async.apply(db.sessionStore.destroy.bind(db.sessionStore), sessionId),
], callback);
});
};
@@ -140,14 +140,13 @@ module.exports = function (User) {
async.each(sids, function (sid, next) {
User.auth.revokeSession(sid, uid, next);
}, next);
}
},
], callback);
};
User.auth.deleteAllSessions = function (callback) {
var _ = require('underscore');
batch.processSortedSet('users:joindate', function (uids, next) {
var sessionKeys = uids.map(function (uid) {
return 'uid:' + uid + ':sessions';
});
@@ -169,10 +168,10 @@ module.exports = function (User) {
async.each(sids, function (sid, next) {
db.sessionStore.destroy(sid, next);
}, next);
}
},
], next);
}
},
], next);
}, {batch: 1000}, callback);
}, { batch: 1000 }, callback);
};
};
};

View File

@@ -1,8 +1,8 @@
'use strict';
var async = require('async');
var db = require('../database');
var plugins = require('../plugins');
module.exports = function (User) {
User.ban = function (uid, until, reason, callback) {
@@ -27,7 +27,7 @@ module.exports = function (User) {
var tasks = [
async.apply(User.setUserField, uid, 'banned', 1),
async.apply(db.sortedSetAdd, 'users:banned', now, uid),
async.apply(db.sortedSetAdd, 'uid:' + uid + ':bans', now, until)
async.apply(db.sortedSetAdd, 'uid:' + uid + ':bans', now, until),
];
if (until > 0 && now < until) {
@@ -49,11 +49,11 @@ module.exports = function (User) {
User.unban = function (uid, callback) {
async.waterfall([
function (next) {
User.setUserFields(uid, {banned: 0, 'banned:expire': 0}, next);
User.setUserFields(uid, { banned: 0, 'banned:expire': 0 }, next);
},
function (next) {
db.sortedSetsRemove(['users:banned', 'users:banned:expire'], uid, next);
}
},
], callback);
};
@@ -75,11 +75,11 @@ module.exports = function (User) {
async.parallel([
async.apply(db.sortedSetRemove.bind(db), 'users:banned:expire', uid),
async.apply(db.sortedSetRemove.bind(db), 'users:banned', uid),
async.apply(User.setUserFields, uid, {banned:0, 'banned:expire': 0})
async.apply(User.setUserFields, uid, { banned: 0, 'banned:expire': 0 }),
], function (err) {
next(err, false);
});
}
},
], callback);
};

View File

@@ -6,7 +6,6 @@ var db = require('../database');
var categories = require('../categories');
module.exports = function (User) {
User.getIgnoredCategories = function (uid, callback) {
db.getSortedSetRange('uid:' + uid + ':ignored:cids', 0, -1, callback);
};
@@ -18,7 +17,7 @@ module.exports = function (User) {
},
all: function (next) {
db.getSortedSetRange('categories:cid', 0, -1, next);
}
},
}, function (err, results) {
if (err) {
return callback(err);
@@ -48,7 +47,7 @@ module.exports = function (User) {
},
function (next) {
db.sortedSetAdd('cid:' + cid + ':ignorers', Date.now(), uid, next);
}
},
], callback);
};
@@ -69,7 +68,7 @@ module.exports = function (User) {
},
function (next) {
db.sortedSetRemove('cid:' + cid + ':ignorers', uid, next);
}
},
], callback);
};
};
};

View File

@@ -9,7 +9,6 @@ var groups = require('../groups');
var meta = require('../meta');
module.exports = function (User) {
User.create = function (data, callback) {
data.username = data.username.trim();
data.userslug = utils.slugify(data.username);
@@ -18,31 +17,31 @@ module.exports = function (User) {
}
User.isDataValid(data, function (err) {
if (err) {
if (err) {
return callback(err);
}
var timestamp = data.timestamp || Date.now();
var userData = {
'username': data.username,
'userslug': data.userslug,
'email': data.email || '',
'joindate': timestamp,
'lastonline': timestamp,
'picture': '',
'fullname': data.fullname || '',
'location': '',
'birthday': '',
'website': '',
'signature': '',
'uploadedpicture': '',
'profileviews': 0,
'reputation': 0,
'postcount': 0,
'topiccount': 0,
'lastposttime': 0,
'banned': 0,
'status': 'online'
username: data.username,
userslug: data.userslug,
email: data.email || '',
joindate: timestamp,
lastonline: timestamp,
picture: '',
fullname: data.fullname || '',
location: '',
birthday: '',
website: '',
signature: '',
uploadedpicture: '',
profileviews: 0,
reputation: 0,
postcount: 0,
topiccount: 0,
lastposttime: 0,
banned: 0,
status: 'online',
};
async.parallel({
@@ -50,8 +49,8 @@ module.exports = function (User) {
renameUsername(userData, next);
},
userData: function (next) {
plugins.fireHook('filter:user.create', {user: userData, data: data}, next);
}
plugins.fireHook('filter:user.create', { user: userData, data: data }, next);
},
}, function (err, results) {
if (err) {
return callback(err);
@@ -106,7 +105,7 @@ module.exports = function (User) {
if (userData.email) {
async.parallel([
async.apply(db.sortedSetAdd, 'email:uid', userData.uid, userData.email.toLowerCase()),
async.apply(db.sortedSetAdd, 'email:sorted', 0, userData.email.toLowerCase() + ':' + userData.uid)
async.apply(db.sortedSetAdd, 'email:sorted', 0, userData.email.toLowerCase() + ':' + userData.uid),
], next);
if (parseInt(userData.uid, 10) !== 1 && parseInt(meta.config.requireEmailConfirmation, 10) === 1) {
@@ -128,13 +127,13 @@ module.exports = function (User) {
async.parallel([
async.apply(User.setUserField, userData.uid, 'password', hash),
async.apply(User.reset.updateExpiry, userData.uid)
async.apply(User.reset.updateExpiry, userData.uid),
], next);
});
},
function (next) {
User.updateDigestSetting(userData.uid, meta.config.dailyDigestFreq, next);
}
},
], next);
},
function (results, next) {
@@ -143,7 +142,7 @@ module.exports = function (User) {
}
plugins.fireHook('action:user.create', {user: userData});
next(null, userData.uid);
}
},
], callback);
});
});
@@ -179,7 +178,7 @@ module.exports = function (User) {
} else {
next();
}
}
},
}, function (err) {
callback(err);
});
@@ -225,5 +224,4 @@ module.exports = function (User) {
});
});
}
};

View File

@@ -9,7 +9,6 @@ var plugins = require('../plugins');
var utils = require('../../public/src/utils');
module.exports = function (User) {
var iconBackgrounds = ['#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3',
'#009688', '#1b5e20', '#33691e', '#827717', '#e65100', '#ff5722', '#795548', '#607d8b'];
@@ -143,7 +142,8 @@ module.exports = function (User) {
}
if (user.picture && user.picture === user.uploadedpicture) {
user.picture = user.uploadedpicture = user.picture.startsWith('http') ? user.picture : nconf.get('relative_path') + user.picture;
user.uploadedpicture = user.picture.startsWith('http') ? user.picture : nconf.get('relative_path') + user.picture;
user.picture = user.uploadedpicture;
} else if (user.uploadedpicture) {
user.uploadedpicture = user.uploadedpicture.startsWith('http') ? user.uploadedpicture : nconf.get('relative_path') + user.uploadedpicture;
}
@@ -152,7 +152,7 @@ module.exports = function (User) {
user.status = User.getStatus(user);
}
for(var i = 0; i < fieldsToRemove.length; ++i) {
for (var i = 0; i < fieldsToRemove.length; i += 1) {
user[fieldsToRemove[i]] = undefined;
}
@@ -182,7 +182,7 @@ module.exports = function (User) {
if (err) {
return callback(err);
}
plugins.fireHook('action:user.set', {uid: uid, field: field, value: value, type: 'set'});
plugins.fireHook('action:user.set', { uid: uid, field: field, value: value, type: 'set' });
callback();
});
};
@@ -195,7 +195,7 @@ module.exports = function (User) {
}
for (var field in data) {
if (data.hasOwnProperty(field)) {
plugins.fireHook('action:user.set', {uid: uid, field: field, value: data[field], type: 'set'});
plugins.fireHook('action:user.set', { uid: uid, field: field, value: data[field], type: 'set' });
}
}
callback();
@@ -208,7 +208,7 @@ module.exports = function (User) {
if (err) {
return callback(err);
}
plugins.fireHook('action:user.set', {uid: uid, field: field, value: value, type: 'increment'});
plugins.fireHook('action:user.set', { uid: uid, field: field, value: value, type: 'increment' });
callback(null, value);
});
@@ -220,10 +220,9 @@ module.exports = function (User) {
if (err) {
return callback(err);
}
plugins.fireHook('action:user.set', {uid: uid, field: field, value: value, type: 'decrement'});
plugins.fireHook('action:user.set', { uid: uid, field: field, value: value, type: 'decrement' });
callback(null, value);
});
};
};

View File

@@ -10,7 +10,6 @@ var plugins = require('../plugins');
var batch = require('../batch');
module.exports = function (User) {
User.delete = function (callerUid, uid, callback) {
if (!parseInt(uid, 10)) {
return callback(new Error('[[error:invalid-uid]]'));
@@ -25,7 +24,7 @@ module.exports = function (User) {
},
function (next) {
User.deleteAccount(uid, next);
}
},
], callback);
};
@@ -34,7 +33,7 @@ module.exports = function (User) {
async.eachSeries(ids, function (pid, next) {
posts.purge(pid, callerUid, next);
}, next);
}, {alwaysStartAt: 0}, callback);
}, { alwaysStartAt: 0 }, callback);
}
function deleteTopics(callerUid, uid, callback) {
@@ -42,7 +41,7 @@ module.exports = function (User) {
async.eachSeries(ids, function (tid, next) {
topics.purge(tid, callerUid, next);
}, next);
}, {alwaysStartAt: 0}, callback);
}, { alwaysStartAt: 0 }, callback);
}
User.deleteAccount = function (uid, callback) {
@@ -57,9 +56,9 @@ module.exports = function (User) {
}
User.getUserFields(uid, ['username', 'userslug', 'fullname', 'email'], next);
},
function (_userData, next) {
function (_userData, next) {
userData = _userData;
plugins.fireHook('static:user.delete', {uid: uid}, next);
plugins.fireHook('static:user.delete', { uid: uid }, next);
},
function (next) {
deleteVotes(uid, next);
@@ -88,7 +87,7 @@ module.exports = function (User) {
if (userData.email) {
async.parallel([
async.apply(db.sortedSetRemove, 'email:uid', userData.email.toLowerCase()),
async.apply(db.sortedSetRemove, 'email:sorted', userData.email.toLowerCase() + ':' + uid)
async.apply(db.sortedSetRemove, 'email:sorted', userData.email.toLowerCase() + ':' + uid),
], next);
} else {
next();
@@ -104,7 +103,7 @@ module.exports = function (User) {
'users:notvalidated',
'digest:day:uids',
'digest:week:uids',
'digest:month:uids'
'digest:month:uids',
], uid, next);
},
function (next) {
@@ -123,7 +122,7 @@ module.exports = function (User) {
'uid:' + uid + ':chat:rooms', 'uid:' + uid + ':chat:rooms:unread',
'uid:' + uid + ':upvote', 'uid:' + uid + ':downvote',
'uid:' + uid + ':ignored:cids', 'uid:' + uid + ':flag:pids',
'uid:' + uid + ':sessions', 'uid:' + uid + ':sessionUUID:sessionId'
'uid:' + uid + ':sessions', 'uid:' + uid + ':sessionUUID:sessionId',
];
db.deleteAll(keys, next);
},
@@ -135,12 +134,12 @@ module.exports = function (User) {
},
function (next) {
groups.leaveAllGroups(uid, next);
}
},
], next);
},
function (results, next) {
db.deleteAll(['followers:' + uid, 'following:' + uid, 'user:' + uid], next);
}
},
], callback);
};
@@ -149,7 +148,7 @@ module.exports = function (User) {
function (next) {
async.parallel({
upvotedPids: async.apply(db.getSortedSetRange, 'uid:' + uid + ':upvote', 0, -1),
downvotedPids: async.apply(db.getSortedSetRange, 'uid:' + uid + ':downvote', 0, -1)
downvotedPids: async.apply(db.getSortedSetRange, 'uid:' + uid + ':downvote', 0, -1),
}, next);
},
function (pids, next) {
@@ -160,7 +159,7 @@ module.exports = function (User) {
async.eachSeries(pids, function (pid, next) {
posts.unvote(pid, uid, next);
}, next);
}
},
], function (err) {
callback(err);
});
@@ -181,9 +180,9 @@ module.exports = function (User) {
async.parallel([
async.apply(db.sortedSetsRemove, roomKeys, uid),
async.apply(db.deleteAll, userKeys)
async.apply(db.deleteAll, userKeys),
], next);
}
},
], function (err) {
callback(err);
});
@@ -202,14 +201,14 @@ module.exports = function (User) {
},
function (next) {
db.delete('uid:' + uid + ':ip', next);
}
},
], callback);
}
function deleteUserFromFollowers(uid, callback) {
async.parallel({
followers: async.apply(db.getSortedSetRange, 'followers:' + uid, 0, -1),
following: async.apply(db.getSortedSetRange, 'following:' + uid, 0, -1)
following: async.apply(db.getSortedSetRange, 'following:' + uid, 0, -1),
}, function (err, results) {
function updateCount(uids, name, fieldName, next) {
async.each(uids, function (uid, next) {
@@ -238,7 +237,7 @@ module.exports = function (User) {
async.parallel([
async.apply(db.sortedSetsRemove, followerSets.concat(followingSets), uid),
async.apply(updateCount, results.following, 'followers:', 'followerCount'),
async.apply(updateCount, results.followers, 'following:', 'followingCount')
async.apply(updateCount, results.followers, 'following:', 'followingCount'),
], callback);
});
}

View File

@@ -1,4 +1,4 @@
"use strict";
'use strict';
var async = require('async');
var winston = require('winston');
@@ -31,7 +31,7 @@ var utils = require('../../public/src/utils');
function (next) {
async.parallel({
topics: async.apply(topics.getLatestTopics, 0, 0, 9, interval),
subscribers: async.apply(Digest.getSubscribers, interval)
subscribers: async.apply(Digest.getSubscribers, interval),
}, next);
},
function (data, next) {
@@ -52,7 +52,7 @@ var utils = require('../../public/src/utils');
data.interval = interval;
Digest.send(data, next);
}
},
], function (err) {
if (err) {
winston.error('[user/jobs] Could not send digests (' + interval + '): ' + err.message);
@@ -72,12 +72,12 @@ var utils = require('../../public/src/utils');
function (subscribers, next) {
plugins.fireHook('filter:digest.subscribers', {
interval: interval,
subscribers: subscribers
subscribers: subscribers,
}, next);
},
function (results, next) {
next(null, results.subscribers);
}
},
], callback);
};
@@ -118,16 +118,15 @@ var utils = require('../../public/src/utils');
site_title: meta.config.title || meta.config.browserTitle || 'NodeBB',
notifications: notifications,
recent: data.topics.topics,
interval: data.interval
interval: data.interval,
});
next();
}
},
], next);
}, next);
}
},
], function (err) {
callback(err);
});
};
}(module.exports));

View File

@@ -13,7 +13,6 @@ var meta = require('../meta');
var emailer = require('../emailer');
(function (UserEmail) {
UserEmail.exists = function (email, callback) {
user.getUidByEmail(email.toLowerCase(), function (err, exists) {
callback(err, !!exists);
@@ -53,11 +52,11 @@ var emailer = require('../emailer');
confirm_code = _confirm_code;
db.setObject('confirm:' + confirm_code, {
email: email.toLowerCase(),
uid: uid
uid: uid,
}, next);
},
function (next) {
db.expireAt('confirm:' + confirm_code, Math.floor(Date.now() / 1000 + 60 * 60 * 24), next);
db.expireAt('confirm:' + confirm_code, Math.floor((Date.now() / 1000) + (60 * 60 * 24)), next);
},
function (next) {
user.getUserField(uid, 'username', next);
@@ -73,17 +72,17 @@ var emailer = require('../emailer');
subject: subject,
template: 'welcome',
uid: uid
uid: uid,
};
if (plugins.hasListeners('action:user.verify')) {
plugins.fireHook('action:user.verify', {uid: uid, data: data});
plugins.fireHook('action:user.verify', { uid: uid, data: data });
next();
} else {
emailer.send('welcome', uid, data, next);
}
});
}
},
], callback);
};
@@ -102,8 +101,8 @@ var emailer = require('../emailer');
db.sortedSetRemove('users:notvalidated', confirmObj.uid, next);
},
function (next) {
plugins.fireHook('action:user.email.confirmed', {uid: confirmObj.uid, email: confirmObj.email}, next);
}
plugins.fireHook('action:user.email.confirmed', { uid: confirmObj.uid, email: confirmObj.email }, next);
},
], function (err) {
callback(err ? new Error('[[error:email-confirm-failed]]') : null);
});
@@ -112,5 +111,4 @@ var emailer = require('../emailer');
}
});
};
}(exports));

View File

@@ -6,7 +6,6 @@ var plugins = require('../plugins');
var db = require('../database');
module.exports = function (User) {
User.follow = function (uid, followuid, callback) {
toggleFollow('follow', uid, followuid, callback);
};
@@ -44,7 +43,7 @@ module.exports = function (User) {
async.apply(db.sortedSetAdd, 'following:' + uid, now, theiruid),
async.apply(db.sortedSetAdd, 'followers:' + theiruid, now, uid),
async.apply(User.incrementUserFieldBy, uid, 'followingCount', 1),
async.apply(User.incrementUserFieldBy, theiruid, 'followerCount', 1)
async.apply(User.incrementUserFieldBy, theiruid, 'followerCount', 1),
], next);
} else {
if (!isFollowing) {
@@ -54,10 +53,10 @@ module.exports = function (User) {
async.apply(db.sortedSetRemove, 'following:' + uid, theiruid),
async.apply(db.sortedSetRemove, 'followers:' + theiruid, uid),
async.apply(User.decrementUserFieldBy, uid, 'followingCount', 1),
async.apply(User.decrementUserFieldBy, theiruid, 'followerCount', 1)
async.apply(User.decrementUserFieldBy, theiruid, 'followerCount', 1),
], next);
}
}
},
], callback);
}
@@ -82,12 +81,12 @@ module.exports = function (User) {
uids: uids,
uid: uid,
start: start,
stop: stop
stop: stop,
}, next);
},
function (data, next) {
User.getUsers(data.uids, uid, next);
}
},
], callback);
}
@@ -97,5 +96,4 @@ module.exports = function (User) {
}
db.isSortedSetMember('following:' + uid, theirid, callback);
};
};

View File

@@ -11,7 +11,9 @@ var topics = require('../topics');
module.exports = function (User) {
User.getLatestBanInfo = function (uid, callback) {
// Simply retrieves the last record of the user's ban, even if they've been unbanned since then.
var timestamp, expiry, reason;
var timestamp;
var expiry;
var reason;
async.waterfall([
async.apply(db.getSortedSetRevRangeWithScores, 'uid:' + uid + ':bans', 0, 0),
@@ -28,7 +30,7 @@ module.exports = function (User) {
function (_reason, next) {
reason = _reason && _reason.length ? _reason[0] : '';
next();
}
},
], function (err) {
if (err) {
return callback(err);
@@ -39,7 +41,7 @@ module.exports = function (User) {
timestamp: timestamp,
expiry: parseInt(expiry, 10),
expiry_readable: new Date(parseInt(expiry, 10)).toString().replace(/:/g, '%3A'),
reason: validator.escape(String(reason))
reason: validator.escape(String(reason)),
});
});
};
@@ -50,12 +52,12 @@ module.exports = function (User) {
async.parallel({
flags: async.apply(db.getSortedSetRevRangeWithScores, 'uid:' + uid + ':flag:pids', 0, 19),
bans: async.apply(db.getSortedSetRevRangeWithScores, 'uid:' + uid + ':bans', 0, 19),
reasons: async.apply(db.getSortedSetRevRangeWithScores, 'banned:' + uid + ':reasons', 0, 19)
reasons: async.apply(db.getSortedSetRevRangeWithScores, 'banned:' + uid + ':reasons', 0, 19),
}, next);
},
function (data, next) {
getFlagMetadata(data, next);
}
},
], function (err, data) {
if (err) {
return callback(err);
@@ -117,9 +119,9 @@ module.exports = function (User) {
function formatBanData(data) {
var reasons = data.reasons.reduce(function (memo, cur) {
memo[cur.score] = cur.value;
return memo;
}, {});
memo[cur.score] = cur.value;
return memo;
}, {});
data.bans = data.bans.map(function (banObj) {
banObj.until = parseInt(banObj.value, 10);

View File

@@ -12,7 +12,6 @@ var utils = require('../../public/src/utils');
module.exports = function (User) {
User.getInvites = function (uid, callback) {
db.getSetMembers('invitation:uid:' + uid, callback);
};
@@ -37,11 +36,11 @@ module.exports = function (User) {
invitations = invitations.map(function (invites, index) {
return {
uid: uids[index],
invitations: invites
invitations: invites,
};
});
next(null, invitations);
}
},
], callback);
};
@@ -68,7 +67,7 @@ module.exports = function (User) {
},
function (next) {
db.setAdd('invitation:uids', uid, next);
}
},
], function (err) {
next(err);
});
@@ -90,12 +89,12 @@ module.exports = function (User) {
registerLink: registerLink,
subject: subject,
username: username,
template: 'invitation'
template: 'invitation',
};
emailer.sendToEmail('invitation', email, meta.config.defaultLang, data, next);
});
}
},
], callback);
};
@@ -114,7 +113,7 @@ module.exports = function (User) {
}
next();
}
},
], callback);
};
@@ -134,11 +133,11 @@ module.exports = function (User) {
},
function (next) {
db.delete('invitation:email:' + email, next);
}
},
], function (err) {
next(err);
});
}
},
], callback);
};
@@ -156,7 +155,7 @@ module.exports = function (User) {
},
function (next) {
db.delete('invitation:email:' + email, next);
}
},
], callback);
};
@@ -173,8 +172,7 @@ module.exports = function (User) {
return db.setRemove('invitation:uids', uid, next);
}
setImmediate(next);
}
},
], callback);
}
};

View File

@@ -22,12 +22,12 @@ module.exports = function (User) {
}
// Terminate any active cron jobs
for(var jobId in jobs) {
for (var jobId in jobs) {
if (jobs.hasOwnProperty(jobId)) {
winston.verbose('[user/jobs] Terminating job (' + jobId + ')');
jobs[jobId].stop();
delete jobs[jobId];
++terminated;
terminated += 1;
}
}
winston.verbose('[user/jobs] ' + terminated + ' jobs terminated');
@@ -37,33 +37,31 @@ module.exports = function (User) {
User.digest.execute('day');
}, null, true);
winston.verbose('[user/jobs] Starting job (digest.daily)');
++started;
started += 1;
jobs['digest.weekly'] = new cronJob('0 ' + digestHour + ' * * 0', function () {
winston.verbose('[user/jobs] Digest job (weekly) started.');
User.digest.execute('week');
}, null, true);
winston.verbose('[user/jobs] Starting job (digest.weekly)');
++started;
started += 1;
jobs['digest.monthly'] = new cronJob('0 ' + digestHour + ' 1 * *', function () {
winston.verbose('[user/jobs] Digest job (monthly) started.');
User.digest.execute('month');
}, null, true);
winston.verbose('[user/jobs] Starting job (digest.monthly)');
++started;
started += 1;
jobs['reset.clean'] = new cronJob('0 0 * * *', User.reset.clean, null, true);
winston.verbose('[user/jobs] Starting job (reset.clean)');
++started;
started += 1;
winston.verbose('[user/jobs] ' + started + ' jobs started');
if (typeof callback === 'function') {
callback();
}
return;
};
};

View File

@@ -11,10 +11,9 @@ var notifications = require('../notifications');
var privileges = require('../privileges');
(function (UserNotifications) {
UserNotifications.get = function (uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null , {read: [], unread: []});
return callback(null, { read: [], unread: [] });
}
getNotifications(uid, 0, 9, function (err, notifications) {
if (err) {
@@ -54,7 +53,7 @@ var privileges = require('../privileges');
},
read: function (next) {
getNotificationsFromSet('uid:' + uid + ':notifications:read', true, uid, start, stop, next);
}
},
}, callback);
}
@@ -64,7 +63,7 @@ var privileges = require('../privileges');
async.waterfall([
async.apply(db.getSortedSetRevRange, set, start, stop),
function (nids, next) {
if(!Array.isArray(nids) || !nids.length) {
if (!Array.isArray(nids) || !nids.length) {
return callback(null, []);
}
@@ -89,7 +88,7 @@ var privileges = require('../privileges');
}
notifications.merge(notifs, next);
}
},
], callback);
}
@@ -137,7 +136,7 @@ var privileges = require('../privileges');
});
db.getObjectsFields(keys, ['mergeId'], next);
}
},
], function (err, mergeIds) {
// A missing (null) mergeId means that notification is counted separately.
mergeIds = mergeIds.map(function (set) {
@@ -146,7 +145,7 @@ var privileges = require('../privileges');
callback(err, mergeIds.reduce(function (count, cur, idx, arr) {
if (cur === null || idx === arr.indexOf(cur)) {
++count;
count += 1;
}
return count;
@@ -195,7 +194,7 @@ var privileges = require('../privileges');
},
function (next) {
db.delete('uid:' + uid + ':notifications:read', next);
}
},
], callback);
};
@@ -229,9 +228,9 @@ var privileges = require('../privileges');
path: '/post/' + postData.pid,
nid: 'tid:' + postData.tid + ':uid:' + uid,
tid: postData.tid,
from: uid
from: uid,
}, next);
}
},
], function (err, notification) {
if (err) {
return winston.error(err);
@@ -254,7 +253,7 @@ var privileges = require('../privileges');
notifications.create({
bodyShort: meta.config.welcomeNotification,
path: path,
nid: 'welcome_' + uid
nid: 'welcome_' + uid,
}, function (err, notification) {
if (err || !notification) {
return callback(err);
@@ -269,7 +268,7 @@ var privileges = require('../privileges');
bodyShort: '[[user:username_taken_workaround, ' + username + ']]',
image: 'brand:logo',
nid: 'username_taken:' + uid,
datetime: Date.now()
datetime: Date.now(),
}, function (err, notification) {
if (!err && notification) {
notifications.push(notification, uid);
@@ -287,5 +286,4 @@ var privileges = require('../privileges');
websockets.in('uid_' + uid).emit('event:notifications.updateCount', count);
});
};
}(exports));

View File

@@ -7,7 +7,6 @@ var db = require('../database');
var Password = require('../password');
module.exports = function (User) {
User.hashPassword = function (password, callback) {
if (!password) {
return callback(null, password);
@@ -34,7 +33,7 @@ module.exports = function (User) {
Password.compare(password, hashedPassword, next);
});
}
},
], callback);
};
@@ -43,5 +42,4 @@ module.exports = function (User) {
callback(err, !!hashedPassword);
});
};
};
};

View File

@@ -14,9 +14,8 @@ var meta = require('../meta');
var db = require('../database');
module.exports = function (User) {
User.uploadPicture = function (uid, picture, callback) {
User.uploadCroppedPicture({uid: uid, file: picture}, callback);
User.uploadCroppedPicture({ uid: uid, file: picture }, callback);
};
User.uploadFromUrl = function (uid, url, callback) {
@@ -46,18 +45,18 @@ module.exports = function (User) {
uid: uid,
image: {
url: url,
name: ''
}
name: '',
},
}, next);
},
function (image, next) {
User.setUserFields(uid, {
uploadedpicture: image.url,
picture: image.url
picture: image.url,
}, function (err) {
next(err, image);
});
}
},
], callback);
};
@@ -66,11 +65,10 @@ module.exports = function (User) {
};
User.updateCoverPicture = function (data, callback) {
var url;
var picture = {
name: 'profileCover',
uid: data.uid
uid: data.uid,
};
if (!data.imageData && data.position) {
@@ -112,18 +110,17 @@ module.exports = function (User) {
} else {
setImmediate(next);
}
}
},
], function (err) {
deleteFile(picture.path);
callback(err, {
url: url
url: url,
});
});
};
User.uploadCroppedPicture = function (data, callback) {
if (parseInt(meta.config.allowProfileImageUploads) !== 1) {
if (parseInt(meta.config.allowProfileImageUploads, 10) !== 1) {
return callback(new Error('[[error:profile-image-uploads-disabled]]'));
}
@@ -147,7 +144,7 @@ module.exports = function (User) {
var picture = {
name: 'profileAvatar',
uid: data.uid
uid: data.uid,
};
async.waterfall([
@@ -168,7 +165,7 @@ module.exports = function (User) {
path: picture.path,
extension: extension,
width: imageDimension,
height: imageDimension
height: imageDimension,
}, next);
},
function (next) {
@@ -180,9 +177,9 @@ module.exports = function (User) {
User.setUserFields(data.uid, {
uploadedpicture: uploadedImage.url,
picture: uploadedImage.url
picture: uploadedImage.url,
}, next);
}
},
], function (err) {
deleteFile(picture.path);
callback(err, uploadedImage);
@@ -208,7 +205,7 @@ module.exports = function (User) {
if (plugins.hasListeners('filter:uploadImage')) {
return plugins.fireHook('filter:uploadImage', {
image: image,
uid: image.uid
uid: image.uid,
}, callback);
}
@@ -233,9 +230,9 @@ module.exports = function (User) {
next(null, {
url: nconf.get('relative_path') + upload.url,
path: upload.path,
name: image.name
name: image.name,
});
}
},
], callback);
}

View File

@@ -6,7 +6,6 @@ var meta = require('../meta');
var privileges = require('../privileges');
module.exports = function (User) {
User.isReadyToPost = function (uid, cid, callback) {
if (parseInt(uid, 10) === 0) {
return callback();
@@ -21,7 +20,7 @@ module.exports = function (User) {
},
isAdminOrMod: function (next) {
privileges.categories.isAdminOrMod(cid, uid, next);
}
},
}, function (err, results) {
if (err) {
return callback(err);
@@ -75,7 +74,7 @@ module.exports = function (User) {
},
function (next) {
User.updateLastOnlineTime(postData.uid, next);
}
},
], callback);
};
@@ -101,5 +100,4 @@ module.exports = function (User) {
callback(err, Array.isArray(pids) ? pids : []);
});
};
};
};

View File

@@ -11,7 +11,6 @@ var groups = require('../groups');
var plugins = require('../plugins');
module.exports = function (User) {
User.updateProfile = function (uid, data, callback) {
var fields = ['username', 'email', 'fullname', 'website', 'location',
'groupTitle', 'birthday', 'signature', 'aboutme'];
@@ -21,7 +20,7 @@ module.exports = function (User) {
async.waterfall([
function (next) {
plugins.fireHook('filter:user.updateProfile', {uid: uid, data: data, fields: fields}, next);
plugins.fireHook('filter:user.updateProfile', { uid: uid, data: data, fields: fields }, next);
},
function (data, next) {
fields = data.fields;
@@ -32,7 +31,7 @@ module.exports = function (User) {
async.apply(isSignatureValid, data),
async.apply(isEmailAvailable, data, updateUid),
async.apply(isUsernameAvailable, data, updateUid),
async.apply(isGroupTitleValid, data)
async.apply(isGroupTitleValid, data),
], function (err) {
next(err);
});
@@ -63,9 +62,9 @@ module.exports = function (User) {
}, next);
},
function (next) {
plugins.fireHook('action:user.updateProfile', {uid: uid, data: data, fields: fields, oldData: oldData});
plugins.fireHook('action:user.updateProfile', { uid: uid, data: data, fields: fields, oldData: oldData });
User.getUserFields(updateUid, ['email', 'username', 'userslug', 'picture', 'icon:text', 'icon:bgColor'], next);
}
},
], callback);
};
@@ -106,7 +105,7 @@ module.exports = function (User) {
},
function (available, next) {
next(!available ? new Error('[[error:email-taken]]') : null);
}
},
], callback);
}
@@ -141,7 +140,7 @@ module.exports = function (User) {
},
function (exists, next) {
next(exists ? new Error('[[error:username-taken]]') : null);
}
},
], callback);
}
@@ -166,7 +165,7 @@ module.exports = function (User) {
}
async.series([
async.apply(db.sortedSetRemove, 'email:uid', oldEmail.toLowerCase()),
async.apply(db.sortedSetRemove, 'email:sorted', oldEmail.toLowerCase() + ':' + uid)
async.apply(db.sortedSetRemove, 'email:sorted', oldEmail.toLowerCase() + ':' + uid),
], function (err) {
next(err);
});
@@ -177,7 +176,7 @@ module.exports = function (User) {
db.sortedSetAdd('email:uid', uid, newEmail.toLowerCase(), next);
},
function (next) {
db.sortedSetAdd('email:sorted', 0, newEmail.toLowerCase() + ':' + uid, next);
db.sortedSetAdd('email:sorted', 0, newEmail.toLowerCase() + ':' + uid, next);
},
function (next) {
db.sortedSetAdd('user:' + uid + ':emails', Date.now(), newEmail + ':' + Date.now(), next);
@@ -193,11 +192,11 @@ module.exports = function (User) {
},
function (next) {
db.sortedSetAdd('users:notvalidated', Date.now(), uid, next);
}
},
], function (err) {
next(err);
});
}
},
], callback);
}
@@ -223,7 +222,7 @@ module.exports = function (User) {
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, 'user:' + uid + ':usernames', Date.now(), newUsername + ':' + Date.now())
async.apply(db.sortedSetAdd, 'user:' + uid + ':usernames', Date.now(), newUsername + ':' + Date.now()),
], next);
},
], callback);
@@ -248,7 +247,7 @@ module.exports = function (User) {
} else {
next();
}
}
},
], callback);
}
@@ -259,7 +258,7 @@ module.exports = function (User) {
},
function (fullname, next) {
updateUidMapping('fullname', uid, newFullname, fullname, next);
}
},
], callback);
}
@@ -289,11 +288,11 @@ module.exports = function (User) {
function (hashedPassword, next) {
async.parallel([
async.apply(User.setUserField, data.uid, 'password', hashedPassword),
async.apply(User.reset.updateExpiry, data.uid)
async.apply(User.reset.updateExpiry, data.uid),
], function (err) {
next(err);
});
}
},
], callback);
};
};

View File

@@ -1,16 +1,16 @@
'use strict';
var async = require('async'),
nconf = require('nconf'),
winston = require('winston'),
var async = require('async');
var nconf = require('nconf');
var winston = require('winston');
user = require('../user'),
utils = require('../../public/src/utils'),
translator = require('../../public/src/modules/translator'),
var user = require('../user');
var utils = require('../../public/src/utils');
var translator = require('../../public/src/modules/translator');
db = require('../database'),
meta = require('../meta'),
emailer = require('../emailer');
var db = require('../database');
var meta = require('../meta');
var emailer = require('../emailer');
(function (UserReset) {
var twoHours = 7200000;
@@ -28,7 +28,7 @@ var async = require('async'),
},
function (issueDate, next) {
next(null, parseInt(issueDate, 10) > Date.now() - twoHours);
}
},
], callback);
};
@@ -36,7 +36,7 @@ var async = require('async'),
var code = utils.generateUUID();
async.parallel([
async.apply(db.setObjectField, 'reset:uid', code, uid),
async.apply(db.sortedSetAdd, 'reset:issueDate', Date.now(), code)
async.apply(db.sortedSetAdd, 'reset:issueDate', Date.now(), code),
], function (err) {
callback(err, code);
});
@@ -48,11 +48,11 @@ var async = require('async'),
db.sortedSetScore('reset:issueDate:uid', uid, next);
},
function (score, next) {
if (score > Date.now() - 1000 * 60) {
if (score > Date.now() - (1000 * 60)) {
return next(new Error('[[error:cant-reset-password-more-than-once-a-minute]]'));
}
next();
}
},
], callback);
}
@@ -88,9 +88,9 @@ var async = require('async'),
reset_link: reset_link,
subject: subject,
template: 'reset',
uid: uid
uid: uid,
}, next);
}
},
], callback);
};
@@ -124,9 +124,9 @@ var async = require('async'),
async.apply(db.sortedSetRemove, 'reset:issueDate', code),
async.apply(db.sortedSetRemove, 'reset:issueDate:uid', uid),
async.apply(user.reset.updateExpiry, uid),
async.apply(user.auth.resetLockout, uid)
async.apply(user.auth.resetLockout, uid),
], next);
}
},
], callback);
};
@@ -148,7 +148,7 @@ var async = require('async'),
},
uids: function (next) {
db.getSortedSetRangeByScore('reset:issueDate:uid', 0, -1, '-inf', Date.now() - twoHours, next);
}
},
}, next);
},
function (results, next) {
@@ -160,10 +160,9 @@ var async = require('async'),
async.parallel([
async.apply(db.deleteObjectFields, 'reset:uid', results.tokens),
async.apply(db.sortedSetRemove, 'reset:issueDate', results.tokens),
async.apply(db.sortedSetRemove, 'reset:issueDate:uid', results.uids)
async.apply(db.sortedSetRemove, 'reset:issueDate:uid', results.uids),
], next);
}
},
], callback);
};
}(exports));

View File

@@ -7,7 +7,6 @@ var plugins = require('../plugins');
var db = require('../database');
module.exports = function (User) {
User.search = function (data, callback) {
var query = data.query || '';
var searchBy = data.searchBy || 'username';
@@ -34,7 +33,7 @@ module.exports = function (User) {
filterAndSortUids(uids, data, next);
},
function (uids, next) {
plugins.fireHook('filter:users.search', {uids: uids, uid: uid}, next);
plugins.fireHook('filter:users.search', { uids: uids, uid: uid }, next);
},
function (data, next) {
var uids = data.uids;
@@ -54,7 +53,7 @@ module.exports = function (User) {
searchResult.timing = (process.elapsedTimeSince(startTime) / 1000).toFixed(2);
searchResult.users = userData;
next(null, searchResult);
}
},
], callback);
};
@@ -135,9 +134,9 @@ module.exports = function (User) {
});
} else {
userData.sort(function (u1, u2) {
if(u1[sortBy] < u2[sortBy]) {
if (u1[sortBy] < u2[sortBy]) {
return -1;
} else if(u1[sortBy] > u2[sortBy]) {
} else if (u1[sortBy] > u2[sortBy]) {
return 1;
}
return 0;
@@ -156,9 +155,9 @@ module.exports = function (User) {
},
function (users, next) {
var diff = process.hrtime(start);
var timing = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(1);
next(null, {timing: timing, users: users});
}
var timing = ((diff[0] * 1e3) + (diff[1] / 1e6)).toFixed(1);
next(null, { timing: timing, users: users });
},
], callback);
}
};

View File

@@ -7,7 +7,6 @@ var db = require('../database');
var plugins = require('../plugins');
module.exports = function (User) {
User.getSettings = function (uid, callback) {
if (!parseInt(uid, 10)) {
return onSettingsLoaded(0, {}, callback);
@@ -18,7 +17,7 @@ module.exports = function (User) {
return callback(err);
}
onSettingsLoaded(uid, settings ? settings : {}, callback);
onSettingsLoaded(uid, settings || {}, callback);
});
};
@@ -36,7 +35,7 @@ module.exports = function (User) {
return callback(err);
}
for (var i = 0; i < settings.length; ++i) {
for (var i = 0; i < settings.length; i += 1) {
settings[i] = settings[i] || {};
settings[i].uid = uids[i];
}
@@ -48,7 +47,7 @@ module.exports = function (User) {
};
function onSettingsLoaded(uid, settings, callback) {
plugins.fireHook('filter:user.getSettings', {uid: uid, settings: settings}, function (err, data) {
plugins.fireHook('filter:user.getSettings', { uid: uid, settings: settings }, function (err, data) {
if (err) {
return callback(err);
}
@@ -102,7 +101,7 @@ module.exports = function (User) {
data.userLang = data.userLang || meta.config.defaultLang;
plugins.fireHook('action:user.saveSettings', {uid: uid, settings: data});
plugins.fireHook('action:user.saveSettings', { uid: uid, settings: data });
var settings = {
showemail: data.showemail,
@@ -120,11 +119,11 @@ module.exports = function (User) {
restrictChat: data.restrictChat,
topicSearchEnabled: data.topicSearchEnabled,
delayImageLoading: data.delayImageLoading,
homePageRoute : ((data.homePageRoute === 'custom' ? data.homePageCustom : data.homePageRoute) || '').replace(/^\//, ''),
homePageRoute: ((data.homePageRoute === 'custom' ? data.homePageCustom : data.homePageRoute) || '').replace(/^\//, ''),
scrollToMyPost: data.scrollToMyPost,
notificationSound: data.notificationSound,
incomingChatSound: data.incomingChatSound,
outgoingChatSound: data.outgoingChatSound
outgoingChatSound: data.outgoingChatSound,
};
if (data.bootswatchSkin) {
@@ -140,7 +139,7 @@ module.exports = function (User) {
},
function (next) {
User.getSettings(uid, next);
}
},
], callback);
};
@@ -155,7 +154,7 @@ module.exports = function (User) {
} else {
next();
}
}
},
], callback);
};

View File

@@ -4,7 +4,6 @@ var async = require('async');
var db = require('../database');
module.exports = function (User) {
User.getIgnoredTids = function (uid, start, stop, callback) {
db.getSortedSetRevRange('uid:' + uid + ':ignored_tids', start, stop, callback);
};
@@ -12,8 +11,7 @@ module.exports = function (User) {
User.addTopicIdToUser = function (uid, tid, timestamp, callback) {
async.parallel([
async.apply(db.sortedSetAdd, 'uid:' + uid + ':topics', timestamp, tid),
async.apply(User.incrementUserFieldBy, uid, 'topiccount', 1)
async.apply(User.incrementUserFieldBy, uid, 'topiccount', 1),
], callback);
};
};
};