mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
Parse int (#6853)
* Store config fields as JSON in the db Fewer parseInts * Remove unnecessary parseInts * remove some dupe code add tests * remove console.log * remove more parseInts * WIP: read meta.configs defaults from defaults.json remove more parseInts * more work * add log for failing test * update admin pwd * fix tests, dont require posts/cache before configs are initialized * handle saves * Test boolean conditions * remove more parseInts * Fix boolean values * remove lots more parseInts * removed json parsing * renamed var to number * categories dont have timestamp
This commit is contained in:
committed by
GitHub
parent
60c58870af
commit
9c022afae1
@@ -7,9 +7,9 @@ before_install:
|
|||||||
before_script:
|
before_script:
|
||||||
- sleep 15 # wait for mongodb to be ready
|
- sleep 15 # wait for mongodb to be ready
|
||||||
- "mongo mydb_test --eval 'db.createUser({user:\"travis\", pwd: \"test\", roles: []});'"
|
- "mongo mydb_test --eval 'db.createUser({user:\"travis\", pwd: \"test\", roles: []});'"
|
||||||
- sh -c "if [ '$DB' = 'mongodb' ]; then node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"mongo\\\",\\\"mongo:host\\\":\\\"127.0.0.1\\\",\\\"mongo:port\\\":27017,\\\"mongo:username\\\":\\\"\\\",\\\"mongo:password\\\":\\\"\\\",\\\"mongo:database\\\":0,\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"abcdef\\\",\\\"admin:password:confirm\\\":\\\"abcdef\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":27017,\\\"database\\\":0}\"; fi"
|
- sh -c "if [ '$DB' = 'mongodb' ]; then node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"mongo\\\",\\\"mongo:host\\\":\\\"127.0.0.1\\\",\\\"mongo:port\\\":27017,\\\"mongo:username\\\":\\\"\\\",\\\"mongo:password\\\":\\\"\\\",\\\"mongo:database\\\":0,\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"hAN3Eg8W\\\",\\\"admin:password:confirm\\\":\\\"hAN3Eg8W\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":27017,\\\"database\\\":0}\"; fi"
|
||||||
- sh -c "if [ '$DB' = 'redis' ]; then node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"redis\\\",\\\"redis:host\\\":\\\"127.0.0.1\\\",\\\"redis:port\\\":6379,\\\"redis:password\\\":\\\"\\\",\\\"redis:database\\\":0,\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"abcdef\\\",\\\"admin:password:confirm\\\":\\\"abcdef\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":6379,\\\"database\\\":0}\"; fi"
|
- sh -c "if [ '$DB' = 'redis' ]; then node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"redis\\\",\\\"redis:host\\\":\\\"127.0.0.1\\\",\\\"redis:port\\\":6379,\\\"redis:password\\\":\\\"\\\",\\\"redis:database\\\":0,\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"hAN3Eg8W\\\",\\\"admin:password:confirm\\\":\\\"hAN3Eg8W\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":6379,\\\"database\\\":0}\"; fi"
|
||||||
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'create database nodebb;' -U postgres; psql -c 'create database travis_ci_test;' -U postgres; node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"postgres\\\",\\\"postgres:host\\\":\\\"127.0.0.1\\\",\\\"postgres:port\\\":5432,\\\"postgres:password\\\":\\\"\\\",\\\"postgres:database\\\":\\\"nodebb\\\",\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"abcdef\\\",\\\"admin:password:confirm\\\":\\\"abcdef\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":5432,\\\"username\\\":\\\"postgres\\\",\\\"database\\\":\\\"travis_ci_test\\\"}\"; fi"
|
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'create database nodebb;' -U postgres; psql -c 'create database travis_ci_test;' -U postgres; node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"postgres\\\",\\\"postgres:host\\\":\\\"127.0.0.1\\\",\\\"postgres:port\\\":5432,\\\"postgres:password\\\":\\\"\\\",\\\"postgres:database\\\":\\\"nodebb\\\",\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"test@example.org\\\",\\\"admin:password\\\":\\\"hAN3Eg8W\\\",\\\"admin:password:confirm\\\":\\\"hAN3Eg8W\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":5432,\\\"username\\\":\\\"postgres\\\",\\\"database\\\":\\\"travis_ci_test\\\"}\"; fi"
|
||||||
after_success:
|
after_success:
|
||||||
- "npm run coveralls"
|
- "npm run coveralls"
|
||||||
language: node_js
|
language: node_js
|
||||||
|
|||||||
@@ -1,9 +1,21 @@
|
|||||||
{
|
{
|
||||||
"title": "NodeBB",
|
"title": "NodeBB",
|
||||||
"showSiteTitle": 1,
|
"showSiteTitle": 1,
|
||||||
|
"loginDays": 14,
|
||||||
|
"loginSeconds": 0,
|
||||||
|
"loginAttempts": 5,
|
||||||
|
"adminReloginDuration": 60,
|
||||||
"postDelay": 10,
|
"postDelay": 10,
|
||||||
"initialPostDelay": 10,
|
"initialPostDelay": 10,
|
||||||
"newbiePostDelay": 120,
|
"newbiePostDelay": 120,
|
||||||
|
"postEditDuration": 0,
|
||||||
|
"postDeleteDuration": 0,
|
||||||
|
"enablePostHistory": 1,
|
||||||
|
"postCacheSize": 5242880,
|
||||||
|
"disableChat": 0,
|
||||||
|
"chatEditDuration": 0,
|
||||||
|
"chatDeleteDuration": 0,
|
||||||
|
"chatMessageDelay": 200,
|
||||||
"newbiePostDelayThreshold": 3,
|
"newbiePostDelayThreshold": 3,
|
||||||
"minimumPostLength": 8,
|
"minimumPostLength": 8,
|
||||||
"maximumPostLength": 32767,
|
"maximumPostLength": 32767,
|
||||||
@@ -17,26 +29,45 @@
|
|||||||
"allowFileUploads": 0,
|
"allowFileUploads": 0,
|
||||||
"allowedFileExtensions": "png,jpg,bmp",
|
"allowedFileExtensions": "png,jpg,bmp",
|
||||||
"allowUserHomePage": 1,
|
"allowUserHomePage": 1,
|
||||||
|
"allowMultipleBadges": 0,
|
||||||
"maximumFileSize": 2048,
|
"maximumFileSize": 2048,
|
||||||
|
"maximumImageWidth": 760,
|
||||||
|
"rejectImageWidth": 5000,
|
||||||
|
"rejectImageHeight": 5000,
|
||||||
|
"resizeImageQuality": 60,
|
||||||
|
"topicThumbSize": 120,
|
||||||
"minimumTitleLength": 3,
|
"minimumTitleLength": 3,
|
||||||
"maximumTitleLength": 255,
|
"maximumTitleLength": 255,
|
||||||
"minimumUsernameLength": 2,
|
"minimumUsernameLength": 2,
|
||||||
"maximumUsernameLength": 16,
|
"maximumUsernameLength": 16,
|
||||||
"minimumPasswordLength": 6,
|
"minimumPasswordLength": 6,
|
||||||
|
"minimumPasswordStrength": 1,
|
||||||
"maximumSignatureLength": 255,
|
"maximumSignatureLength": 255,
|
||||||
"maximumAboutMeLength": 1000,
|
"maximumAboutMeLength": 1000,
|
||||||
|
"maximumUsersInChatRoom": 0,
|
||||||
"maximumChatMessageLength": 1000,
|
"maximumChatMessageLength": 1000,
|
||||||
"maximumProfileImageSize": 256,
|
"maximumProfileImageSize": 256,
|
||||||
"maximumCoverImageSize": 2048,
|
"maximumCoverImageSize": 2048,
|
||||||
"profileImageDimension": 200,
|
"profileImageDimension": 200,
|
||||||
|
"profile:convertProfileImageToPNG": 0,
|
||||||
|
"profile:keepAllUserImages": 0,
|
||||||
"requireEmailConfirmation": 0,
|
"requireEmailConfirmation": 0,
|
||||||
"allowProfileImageUploads": 1,
|
"allowProfileImageUploads": 1,
|
||||||
"teaserPost": "last-reply",
|
"teaserPost": "last-reply",
|
||||||
"allowPrivateGroups": 1,
|
"allowPrivateGroups": 1,
|
||||||
|
"allowGroupCreation": 0,
|
||||||
"unreadCutoff": 2,
|
"unreadCutoff": 2,
|
||||||
"bookmarkThreshold": 5,
|
"bookmarkThreshold": 5,
|
||||||
"autoDetectLang": 1,
|
"autoDetectLang": 1,
|
||||||
|
"reputation:disabled": 0,
|
||||||
|
"downvote:disabled": 0,
|
||||||
|
"disableSignatures": 0,
|
||||||
"min:rep:flag": 0,
|
"min:rep:flag": 0,
|
||||||
|
"min:rep:profile-picture": 0,
|
||||||
|
"min:rep:cover-picture": 0,
|
||||||
|
"min:rep:website": 0,
|
||||||
|
"min:rep:aboutme": 0,
|
||||||
|
"min:rep:signature": 0,
|
||||||
"notificationType_upvote": "notification",
|
"notificationType_upvote": "notification",
|
||||||
"notificationType_new-topic": "notification",
|
"notificationType_new-topic": "notification",
|
||||||
"notificationType_new-reply": "notification",
|
"notificationType_new-reply": "notification",
|
||||||
@@ -45,7 +76,36 @@
|
|||||||
"notificationType_group-invite": "notification",
|
"notificationType_group-invite": "notification",
|
||||||
"notificationType_mention": "notification",
|
"notificationType_mention": "notification",
|
||||||
"notificationType_new-register": "notification",
|
"notificationType_new-register": "notification",
|
||||||
"notificationType_post-queue": "notification",
|
"notificationType_post-queue": "notification",
|
||||||
"notificationType_new-post-flag": "notification",
|
"notificationType_new-post-flag": "notification",
|
||||||
"notificationType_new-user-flag": "notification"
|
"notificationType_new-user-flag": "notification",
|
||||||
}
|
"topicStaleDays": 60,
|
||||||
|
"maxTopicsPerPage": 20,
|
||||||
|
"maxPostsPerPage": 20,
|
||||||
|
"topicsPerPage": 20,
|
||||||
|
"postsPerPage": 20,
|
||||||
|
"userSearchResultsPerPage": 50,
|
||||||
|
"maximumGroupNameLength": 255,
|
||||||
|
"preventTopicDeleteAfterReplies": 0,
|
||||||
|
"sitemapTopics": 500,
|
||||||
|
"maintenanceMode": 0,
|
||||||
|
"votesArePublic": 0,
|
||||||
|
"maximumInvites": 0,
|
||||||
|
"username:disableEdit": 0,
|
||||||
|
"email:disableEdit": 0,
|
||||||
|
"hideFullname": 0,
|
||||||
|
"allowGuestHandles": 0,
|
||||||
|
"disableRecentCategoryFilter": 0,
|
||||||
|
"maximumRelatedTopics": 0,
|
||||||
|
"disableEmailSubscriptions": 0,
|
||||||
|
"emailConfirmInterval": 10,
|
||||||
|
"inviteExpiration": 7,
|
||||||
|
"digestHour": 17,
|
||||||
|
"passwordExpiryDays": 0,
|
||||||
|
"hsts-maxage": 31536000,
|
||||||
|
"hsts-subdomains": 0,
|
||||||
|
"hsts-preload": 0,
|
||||||
|
"hsts-enabled": 0,
|
||||||
|
"eventLoopLagThreshold": 100,
|
||||||
|
"eventLoopInterval": 500
|
||||||
|
}
|
||||||
@@ -399,6 +399,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
isNumber: function (n) {
|
isNumber: function (n) {
|
||||||
|
// `isFinite('') === true` so isNan parseFloat check is necessary
|
||||||
return !isNaN(parseFloat(n)) && isFinite(n);
|
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ var validator = require('validator');
|
|||||||
|
|
||||||
var db = require('../database');
|
var db = require('../database');
|
||||||
|
|
||||||
const intFields = ['cid', 'parentCid', 'disabled', 'isSection', 'order', 'topic_count', 'post_count'];
|
const intFields = [
|
||||||
|
'cid', 'parentCid', 'disabled', 'isSection', 'order',
|
||||||
|
'topic_count', 'post_count',
|
||||||
|
];
|
||||||
|
|
||||||
module.exports = function (Categories) {
|
module.exports = function (Categories) {
|
||||||
Categories.getCategoriesFields = function (cids, fields, callback) {
|
Categories.getCategoriesFields = function (cids, fields, callback) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ var helpers = require('../helpers');
|
|||||||
var chatsController = module.exports;
|
var chatsController = module.exports;
|
||||||
|
|
||||||
chatsController.get = function (req, res, callback) {
|
chatsController.get = function (req, res, callback) {
|
||||||
if (parseInt(meta.config.disableChat, 10) === 1) {
|
if (meta.config.disableChat) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,18 +31,18 @@ editController.get = function (req, res, callback) {
|
|||||||
if (!userData) {
|
if (!userData) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
userData.maximumSignatureLength = parseInt(meta.config.maximumSignatureLength, 10) || 255;
|
userData.maximumSignatureLength = meta.config.maximumSignatureLength;
|
||||||
userData.maximumAboutMeLength = parseInt(meta.config.maximumAboutMeLength, 10) || 1000;
|
userData.maximumAboutMeLength = meta.config.maximumAboutMeLength;
|
||||||
userData.maximumProfileImageSize = parseInt(meta.config.maximumProfileImageSize, 10);
|
userData.maximumProfileImageSize = meta.config.maximumProfileImageSize;
|
||||||
userData.allowProfilePicture = !userData.isSelf || parseInt(userData.reputation, 10) >= (parseInt(meta.config['min:rep:profile-picture'], 10) || 0);
|
userData.allowProfilePicture = !userData.isSelf || userData.reputation >= meta.config['min:rep:profile-picture'];
|
||||||
userData.allowCoverPicture = !userData.isSelf || parseInt(userData.reputation, 10) >= (parseInt(meta.config['min:rep:cover-picture'], 10) || 0);
|
userData.allowCoverPicture = !userData.isSelf || userData.reputation >= meta.config['min:rep:cover-picture'];
|
||||||
userData.allowProfileImageUploads = parseInt(meta.config.allowProfileImageUploads, 10) === 1;
|
userData.allowProfileImageUploads = meta.config.allowProfileImageUploads;
|
||||||
userData.allowMultipleBadges = parseInt(meta.config.allowMultipleBadges, 10) === 1;
|
userData.allowMultipleBadges = meta.config.allowMultipleBadges === 1;
|
||||||
userData.allowAccountDelete = parseInt(meta.config.allowAccountDelete, 10) === 1;
|
userData.allowAccountDelete = meta.config.allowAccountDelete === 1;
|
||||||
userData.allowWebsite = !userData.isSelf || parseInt(userData.reputation, 10) >= (parseInt(meta.config['min:rep:website'], 10) || 0);
|
userData.allowWebsite = !userData.isSelf || userData.reputation >= meta.config['min:rep:website'];
|
||||||
userData.allowAboutMe = !userData.isSelf || parseInt(userData.reputation, 10) >= (parseInt(meta.config['min:rep:aboutme'], 10) || 0);
|
userData.allowAboutMe = !userData.isSelf || userData.reputation >= meta.config['min:rep:aboutme'];
|
||||||
userData.allowSignature = results.canUseSignature && (!userData.isSelf || parseInt(userData.reputation, 10) >= (parseInt(meta.config['min:rep:signature'], 10) || 0));
|
userData.allowSignature = results.canUseSignature && (!userData.isSelf || userData.reputation >= meta.config['min:rep:signature']);
|
||||||
userData.profileImageDimension = parseInt(meta.config.profileImageDimension, 10) || 200;
|
userData.profileImageDimension = meta.config.profileImageDimension || 200;
|
||||||
userData.defaultAvatar = user.getDefaultAvatar();
|
userData.defaultAvatar = user.getDefaultAvatar();
|
||||||
|
|
||||||
userData.groups = userData.groups.filter(function (group) {
|
userData.groups = userData.groups.filter(function (group) {
|
||||||
@@ -103,8 +103,8 @@ function renderRoute(name, req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (name === 'password') {
|
if (name === 'password') {
|
||||||
userData.minimumPasswordLength = parseInt(meta.config.minimumPasswordLength, 10);
|
userData.minimumPasswordLength = meta.config.minimumPasswordLength;
|
||||||
userData.minimumPasswordStrength = parseInt(meta.config.minimumPasswordStrength || 1, 10);
|
userData.minimumPasswordStrength = meta.config.minimumPasswordStrength;
|
||||||
}
|
}
|
||||||
|
|
||||||
userData.title = '[[pages:account/edit/' + name + ', ' + userData.username + ']]';
|
userData.title = '[[pages:account/edit/' + name + ', ' + userData.username + ']]';
|
||||||
|
|||||||
@@ -125,13 +125,13 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
|
|||||||
|
|
||||||
userData.emailClass = 'hide';
|
userData.emailClass = 'hide';
|
||||||
|
|
||||||
if (!isAdmin && !isGlobalModerator && !isSelf && (!userSettings.showemail || parseInt(meta.config.hideEmail, 10) === 1)) {
|
if (!isAdmin && !isGlobalModerator && !isSelf && (!userSettings.showemail || meta.config.hideEmail)) {
|
||||||
userData.email = '';
|
userData.email = '';
|
||||||
} else if (!userSettings.showemail) {
|
} else if (!userSettings.showemail) {
|
||||||
userData.emailClass = '';
|
userData.emailClass = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isAdmin && !isGlobalModerator && !isSelf && (!userSettings.showfullname || parseInt(meta.config.hideFullname, 10) === 1)) {
|
if (!isAdmin && !isGlobalModerator && !isSelf && (!userSettings.showfullname || meta.config.hideFullname)) {
|
||||||
userData.fullname = '';
|
userData.fullname = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,15 +159,15 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
|
|||||||
userData.isSelfOrAdminOrGlobalModerator = isSelf || isAdmin || isGlobalModerator;
|
userData.isSelfOrAdminOrGlobalModerator = isSelf || isAdmin || isGlobalModerator;
|
||||||
userData.canEdit = results.canEdit;
|
userData.canEdit = results.canEdit;
|
||||||
userData.canBan = results.canBanUser;
|
userData.canBan = results.canBanUser;
|
||||||
userData.canChangePassword = isAdmin || (isSelf && parseInt(meta.config['password:disableEdit'], 10) !== 1);
|
userData.canChangePassword = isAdmin || (isSelf && !meta.config['password:disableEdit']);
|
||||||
userData.isSelf = isSelf;
|
userData.isSelf = isSelf;
|
||||||
userData.isFollowing = results.isFollowing;
|
userData.isFollowing = results.isFollowing;
|
||||||
userData.showHidden = isSelf || isAdmin || (isGlobalModerator && !results.isTargetAdmin);
|
userData.showHidden = isSelf || isAdmin || (isGlobalModerator && !results.isTargetAdmin);
|
||||||
userData.groups = Array.isArray(results.groups) && results.groups.length ? results.groups[0] : [];
|
userData.groups = Array.isArray(results.groups) && results.groups.length ? results.groups[0] : [];
|
||||||
userData.disableSignatures = meta.config.disableSignatures !== undefined && parseInt(meta.config.disableSignatures, 10) === 1;
|
userData.disableSignatures = meta.config.disableSignatures === 1;
|
||||||
userData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
|
userData['reputation:disabled'] = meta.config['reputation:disabled'] === 1;
|
||||||
userData['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1;
|
userData['downvote:disabled'] = meta.config['downvote:disabled'] === 1;
|
||||||
userData['email:confirmed'] = !!parseInt(userData['email:confirmed'], 10);
|
userData['email:confirmed'] = !!userData['email:confirmed'];
|
||||||
userData.profile_links = filterLinks(results.profile_menu.links, {
|
userData.profile_links = filterLinks(results.profile_menu.links, {
|
||||||
self: isSelf,
|
self: isSelf,
|
||||||
other: !isSelf,
|
other: !isSelf,
|
||||||
@@ -200,8 +200,8 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
userData['cover:position'] = validator.escape(String(userData['cover:position'] || '50% 50%'));
|
userData['cover:position'] = validator.escape(String(userData['cover:position'] || '50% 50%'));
|
||||||
userData['username:disableEdit'] = !userData.isAdmin && parseInt(meta.config['username:disableEdit'], 10) === 1;
|
userData['username:disableEdit'] = !userData.isAdmin && meta.config['username:disableEdit'];
|
||||||
userData['email:disableEdit'] = !userData.isAdmin && parseInt(meta.config['email:disableEdit'], 10) === 1;
|
userData['email:disableEdit'] = !userData.isAdmin && meta.config['email:disableEdit'];
|
||||||
|
|
||||||
next(null, userData);
|
next(null, userData);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ profileController.get = function (req, res, callback) {
|
|||||||
|
|
||||||
req.session.uids_viewed = req.session.uids_viewed || {};
|
req.session.uids_viewed = req.session.uids_viewed || {};
|
||||||
|
|
||||||
if (req.uid !== parseInt(userData.uid, 10) && (!req.session.uids_viewed[userData.uid] || req.session.uids_viewed[userData.uid] < Date.now() - 3600000)) {
|
if (req.uid !== userData.uid && (!req.session.uids_viewed[userData.uid] || req.session.uids_viewed[userData.uid] < Date.now() - 3600000)) {
|
||||||
user.incrementUserFieldBy(userData.uid, 'profileviews', 1);
|
user.incrementUserFieldBy(userData.uid, 'profileviews', 1);
|
||||||
req.session.uids_viewed[userData.uid] = Date.now();
|
req.session.uids_viewed[userData.uid] = Date.now();
|
||||||
}
|
}
|
||||||
@@ -68,23 +68,21 @@ profileController.get = function (req, res, callback) {
|
|||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
|
if (meta.config['reputation:disabled']) {
|
||||||
delete userData.reputation;
|
delete userData.reputation;
|
||||||
}
|
}
|
||||||
|
|
||||||
userData.posts = results.posts.posts.filter(function (p) {
|
userData.posts = results.posts.posts.filter(p => p && !p.deleted);
|
||||||
return p && parseInt(p.deleted, 10) !== 1;
|
|
||||||
});
|
|
||||||
userData.hasPrivateChat = results.hasPrivateChat;
|
userData.hasPrivateChat = results.hasPrivateChat;
|
||||||
userData.aboutme = translator.escape(results.aboutme);
|
userData.aboutme = translator.escape(results.aboutme);
|
||||||
userData.nextStart = results.posts.nextStart;
|
userData.nextStart = results.posts.nextStart;
|
||||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username }]);
|
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username }]);
|
||||||
userData.title = userData.username;
|
userData.title = userData.username;
|
||||||
userData.allowCoverPicture = !userData.isSelf || parseInt(userData.reputation, 10) >= (parseInt(meta.config['min:rep:cover-picture'], 10) || 0);
|
userData.allowCoverPicture = !userData.isSelf || userData.reputation >= (meta.config['min:rep:cover-picture'] || 0);
|
||||||
var pageCount = Math.ceil(userData.postcount / itemsPerPage);
|
var pageCount = Math.ceil(userData.postcount / itemsPerPage);
|
||||||
userData.pagination = pagination.create(page, pageCount, req.query);
|
userData.pagination = pagination.create(page, pageCount, req.query);
|
||||||
|
|
||||||
if (!parseInt(userData.profileviews, 10)) {
|
if (!userData.profileviews) {
|
||||||
userData.profileviews = 1;
|
userData.profileviews = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ settingsController.get = function (req, res, callback) {
|
|||||||
function (results) {
|
function (results) {
|
||||||
userData.homePageRoutes = results.routes;
|
userData.homePageRoutes = results.routes;
|
||||||
userData.notificationSettings = results.notificationSettings;
|
userData.notificationSettings = results.notificationSettings;
|
||||||
userData.disableEmailSubscriptions = parseInt(meta.config.disableEmailSubscriptions, 10) === 1;
|
userData.disableEmailSubscriptions = meta.config.disableEmailSubscriptions;
|
||||||
|
|
||||||
userData.dailyDigestFreqOptions = [
|
userData.dailyDigestFreqOptions = [
|
||||||
{ value: 'off', name: '[[user:digest_off]]', selected: userData.settings.dailyDigestFreq === 'off' },
|
{ value: 'off', name: '[[user:digest_off]]', selected: userData.settings.dailyDigestFreq === 'off' },
|
||||||
@@ -162,17 +162,17 @@ settingsController.get = function (req, res, callback) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
userData.disableCustomUserSkins = parseInt(meta.config.disableCustomUserSkins, 10) === 1;
|
userData.disableCustomUserSkins = meta.config.disableCustomUserSkins;
|
||||||
|
|
||||||
userData.allowUserHomePage = parseInt(meta.config.allowUserHomePage, 10) === 1;
|
userData.allowUserHomePage = meta.config.allowUserHomePage;
|
||||||
|
|
||||||
userData.hideFullname = parseInt(meta.config.hideFullname, 10) === 1;
|
userData.hideFullname = meta.config.hideFullname;
|
||||||
userData.hideEmail = parseInt(meta.config.hideEmail, 10) === 1;
|
userData.hideEmail = meta.config.hideEmail;
|
||||||
|
|
||||||
userData.inTopicSearchAvailable = plugins.hasListeners('filter:topic.search');
|
userData.inTopicSearchAvailable = plugins.hasListeners('filter:topic.search');
|
||||||
|
|
||||||
userData.maxTopicsPerPage = parseInt(meta.config.maxTopicsPerPage, 10) || 20;
|
userData.maxTopicsPerPage = meta.config.maxTopicsPerPage;
|
||||||
userData.maxPostsPerPage = parseInt(meta.config.maxPostsPerPage, 10) || 20;
|
userData.maxPostsPerPage = meta.config.maxPostsPerPage;
|
||||||
|
|
||||||
userData.title = '[[pages:account/settings]]';
|
userData.title = '[[pages:account/settings]]';
|
||||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:settings]]' }]);
|
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:settings]]' }]);
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ uploadsController.get = function (req, res, callback) {
|
|||||||
});
|
});
|
||||||
var pageCount = Math.ceil(results.itemCount / itemsPerPage);
|
var pageCount = Math.ceil(results.itemCount / itemsPerPage);
|
||||||
userData.pagination = pagination.create(page, pageCount, req.query);
|
userData.pagination = pagination.create(page, pageCount, req.query);
|
||||||
userData.privateUploads = parseInt(meta.config.privateUploads, 10) === 1;
|
userData.privateUploads = meta.config.privateUploads === 1;
|
||||||
userData.title = '[[pages:account/uploads, ' + userData.username + ']]';
|
userData.title = '[[pages:account/uploads, ' + userData.username + ']]';
|
||||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[global:uploads]]' }]);
|
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[global:uploads]]' }]);
|
||||||
res.render('account/uploads', userData);
|
res.render('account/uploads', userData);
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ groupsController.get = function (req, res, callback) {
|
|||||||
res.render('admin/manage/group', {
|
res.render('admin/manage/group', {
|
||||||
group: result.group,
|
group: result.group,
|
||||||
groupNames: result.groupNames,
|
groupNames: result.groupNames,
|
||||||
allowPrivateGroups: parseInt(meta.config.allowPrivateGroups, 10) === 1,
|
allowPrivateGroups: meta.config.allowPrivateGroups,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ languagesController.get = function (req, res, next) {
|
|||||||
|
|
||||||
res.render('admin/general/languages', {
|
res.render('admin/general/languages', {
|
||||||
languages: languages,
|
languages: languages,
|
||||||
autoDetectLang: parseInt(meta.config.autoDetectLang, 10) === 1,
|
autoDetectLang: meta.config.autoDetectLang,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
], next);
|
], next);
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ function getUsers(set, section, min, max, req, res, next) {
|
|||||||
function render(req, res, data) {
|
function render(req, res, data) {
|
||||||
data.search_display = 'hidden';
|
data.search_display = 'hidden';
|
||||||
data.pagination = pagination.create(data.page, data.pageCount, req.query);
|
data.pagination = pagination.create(data.page, data.pageCount, req.query);
|
||||||
data.requireEmailConfirmation = parseInt(meta.config.requireEmailConfirmation, 10) === 1;
|
data.requireEmailConfirmation = meta.config.requireEmailConfirmation;
|
||||||
|
|
||||||
var registrationType = meta.config.registrationType;
|
var registrationType = meta.config.registrationType;
|
||||||
|
|
||||||
|
|||||||
@@ -22,23 +22,23 @@ apiController.loadConfig = function (req, callback) {
|
|||||||
config.siteTitle = validator.escape(String(meta.config.title || meta.config.browserTitle || 'NodeBB'));
|
config.siteTitle = validator.escape(String(meta.config.title || meta.config.browserTitle || 'NodeBB'));
|
||||||
config.browserTitle = validator.escape(String(meta.config.browserTitle || meta.config.title || 'NodeBB'));
|
config.browserTitle = validator.escape(String(meta.config.browserTitle || meta.config.title || 'NodeBB'));
|
||||||
config.titleLayout = (meta.config.titleLayout || '{pageTitle} | {browserTitle}').replace(/{/g, '{').replace(/}/g, '}');
|
config.titleLayout = (meta.config.titleLayout || '{pageTitle} | {browserTitle}').replace(/{/g, '{').replace(/}/g, '}');
|
||||||
config.showSiteTitle = parseInt(meta.config.showSiteTitle, 10) === 1;
|
config.showSiteTitle = meta.config.showSiteTitle === 1;
|
||||||
config.minimumTitleLength = meta.config.minimumTitleLength;
|
config.minimumTitleLength = meta.config.minimumTitleLength;
|
||||||
config.maximumTitleLength = meta.config.maximumTitleLength;
|
config.maximumTitleLength = meta.config.maximumTitleLength;
|
||||||
config.minimumPostLength = meta.config.minimumPostLength;
|
config.minimumPostLength = meta.config.minimumPostLength;
|
||||||
config.maximumPostLength = meta.config.maximumPostLength;
|
config.maximumPostLength = meta.config.maximumPostLength;
|
||||||
config.minimumTagsPerTopic = parseInt(meta.config.minimumTagsPerTopic || 0, 10);
|
config.minimumTagsPerTopic = meta.config.minimumTagsPerTopic || 0;
|
||||||
config.maximumTagsPerTopic = parseInt(meta.config.maximumTagsPerTopic || 5, 10);
|
config.maximumTagsPerTopic = meta.config.maximumTagsPerTopic || 5;
|
||||||
config.minimumTagLength = meta.config.minimumTagLength || 3;
|
config.minimumTagLength = meta.config.minimumTagLength || 3;
|
||||||
config.maximumTagLength = meta.config.maximumTagLength || 15;
|
config.maximumTagLength = meta.config.maximumTagLength || 15;
|
||||||
config.useOutgoingLinksPage = parseInt(meta.config.useOutgoingLinksPage, 10) === 1;
|
config.useOutgoingLinksPage = meta.config.useOutgoingLinksPage === 1;
|
||||||
config.allowGuestHandles = parseInt(meta.config.allowGuestHandles, 10) === 1;
|
config.allowGuestHandles = meta.config.allowGuestHandles === 1;
|
||||||
config.allowFileUploads = parseInt(meta.config.allowFileUploads, 10) === 1;
|
config.allowFileUploads = meta.config.allowFileUploads === 1;
|
||||||
config.allowTopicsThumbnail = parseInt(meta.config.allowTopicsThumbnail, 10) === 1;
|
config.allowTopicsThumbnail = meta.config.allowTopicsThumbnail === 1;
|
||||||
config.usePagination = parseInt(meta.config.usePagination, 10) === 1;
|
config.usePagination = meta.config.usePagination === 1;
|
||||||
config.disableChat = parseInt(meta.config.disableChat, 10) === 1;
|
config.disableChat = meta.config.disableChat === 1;
|
||||||
config.disableChatMessageEditing = parseInt(meta.config.disableChatMessageEditing, 10) === 1;
|
config.disableChatMessageEditing = meta.config.disableChatMessageEditing === 1;
|
||||||
config.maximumChatMessageLength = parseInt(meta.config.maximumChatMessageLength, 10) || 1000;
|
config.maximumChatMessageLength = meta.config.maximumChatMessageLength || 1000;
|
||||||
config.socketioTransports = nconf.get('socket.io:transports') || ['polling', 'websocket'];
|
config.socketioTransports = nconf.get('socket.io:transports') || ['polling', 'websocket'];
|
||||||
config.websocketAddress = nconf.get('socket.io:address') || '';
|
config.websocketAddress = nconf.get('socket.io:address') || '';
|
||||||
config.maxReconnectionAttempts = meta.config.maxReconnectionAttempts || 5;
|
config.maxReconnectionAttempts = meta.config.maxReconnectionAttempts || 5;
|
||||||
@@ -53,15 +53,15 @@ apiController.loadConfig = function (req, callback) {
|
|||||||
config.loggedIn = !!req.user;
|
config.loggedIn = !!req.user;
|
||||||
config.uid = req.uid;
|
config.uid = req.uid;
|
||||||
config['cache-buster'] = meta.config['cache-buster'] || '';
|
config['cache-buster'] = meta.config['cache-buster'] || '';
|
||||||
config.requireEmailConfirmation = parseInt(meta.config.requireEmailConfirmation, 10) === 1;
|
config.requireEmailConfirmation = meta.config.requireEmailConfirmation === 1;
|
||||||
config.topicPostSort = meta.config.topicPostSort || 'oldest_to_newest';
|
config.topicPostSort = meta.config.topicPostSort || 'oldest_to_newest';
|
||||||
config.categoryTopicSort = meta.config.categoryTopicSort || 'newest_to_oldest';
|
config.categoryTopicSort = meta.config.categoryTopicSort || 'newest_to_oldest';
|
||||||
config.csrf_token = req.csrfToken && req.csrfToken();
|
config.csrf_token = req.csrfToken && req.csrfToken();
|
||||||
config.searchEnabled = plugins.hasListeners('filter:search.query');
|
config.searchEnabled = plugins.hasListeners('filter:search.query');
|
||||||
config.bootswatchSkin = meta.config.bootswatchSkin || 'noskin';
|
config.bootswatchSkin = meta.config.bootswatchSkin || 'noskin';
|
||||||
config.defaultBootswatchSkin = meta.config.bootswatchSkin || 'noskin';
|
config.defaultBootswatchSkin = meta.config.bootswatchSkin || 'noskin';
|
||||||
config.enablePostHistory = parseInt(meta.config.enablePostHistory || 1, 10) === 1;
|
config.enablePostHistory = (meta.config.enablePostHistory || 1) === 1;
|
||||||
config.notificationAlertTimeout = parseInt(meta.config.notificationAlertTimeout, 10) || 5000;
|
config.notificationAlertTimeout = meta.config.notificationAlertTimeout || 5000;
|
||||||
|
|
||||||
if (config.useOutgoingLinksPage) {
|
if (config.useOutgoingLinksPage) {
|
||||||
config.outgoingLinksWhitelist = meta.config['outgoingLinks:whitelist'];
|
config.outgoingLinksWhitelist = meta.config['outgoingLinks:whitelist'];
|
||||||
@@ -71,7 +71,7 @@ apiController.loadConfig = function (req, callback) {
|
|||||||
config.timeagoCutoff = timeagoCutoff !== '' ? Math.max(0, parseInt(timeagoCutoff, 10)) : timeagoCutoff;
|
config.timeagoCutoff = timeagoCutoff !== '' ? Math.max(0, parseInt(timeagoCutoff, 10)) : timeagoCutoff;
|
||||||
|
|
||||||
config.cookies = {
|
config.cookies = {
|
||||||
enabled: parseInt(meta.config.cookieConsentEnabled, 10) === 1,
|
enabled: meta.config.cookieConsentEnabled === 1,
|
||||||
message: translator.escape(validator.escape(meta.config.cookieConsentMessage || '[[global:cookies.message]]')).replace(/\\/g, '\\\\'),
|
message: translator.escape(validator.escape(meta.config.cookieConsentMessage || '[[global:cookies.message]]')).replace(/\\/g, '\\\\'),
|
||||||
dismiss: translator.escape(validator.escape(meta.config.cookieConsentDismiss || '[[global:cookies.accept]]')).replace(/\\/g, '\\\\'),
|
dismiss: translator.escape(validator.escape(meta.config.cookieConsentDismiss || '[[global:cookies.accept]]')).replace(/\\/g, '\\\\'),
|
||||||
link: translator.escape(validator.escape(meta.config.cookieConsentLink || '[[global:cookies.learn_more]]')).replace(/\\/g, '\\\\'),
|
link: translator.escape(validator.escape(meta.config.cookieConsentLink || '[[global:cookies.learn_more]]')).replace(/\\/g, '\\\\'),
|
||||||
@@ -95,7 +95,7 @@ apiController.loadConfig = function (req, callback) {
|
|||||||
config.categoryTopicSort = settings.categoryTopicSort || config.categoryTopicSort;
|
config.categoryTopicSort = settings.categoryTopicSort || config.categoryTopicSort;
|
||||||
config.topicSearchEnabled = settings.topicSearchEnabled || false;
|
config.topicSearchEnabled = settings.topicSearchEnabled || false;
|
||||||
config.delayImageLoading = settings.delayImageLoading !== undefined ? settings.delayImageLoading : true;
|
config.delayImageLoading = settings.delayImageLoading !== undefined ? settings.delayImageLoading : true;
|
||||||
config.bootswatchSkin = (parseInt(meta.config.disableCustomUserSkins, 10) !== 1 && settings.bootswatchSkin && settings.bootswatchSkin !== 'default') ? settings.bootswatchSkin : config.bootswatchSkin;
|
config.bootswatchSkin = (meta.config.disableCustomUserSkins !== 1 && settings.bootswatchSkin && settings.bootswatchSkin !== 'default') ? settings.bootswatchSkin : config.bootswatchSkin;
|
||||||
plugins.fireHook('filter:config.get', config, next);
|
plugins.fireHook('filter:config.get', config, next);
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ function continueLogin(req, res, next) {
|
|||||||
|
|
||||||
// Alter user cookie depending on passed-in option
|
// Alter user cookie depending on passed-in option
|
||||||
if (req.body.remember === 'on') {
|
if (req.body.remember === 'on') {
|
||||||
var duration = 1000 * 60 * 60 * 24 * (parseInt(meta.config.loginDays, 10) || 14);
|
var duration = 1000 * 60 * 60 * 24 * meta.config.loginDays;
|
||||||
req.session.cookie.maxAge = duration;
|
req.session.cookie.maxAge = duration;
|
||||||
req.session.cookie.expires = new Date(Date.now() + duration);
|
req.session.cookie.expires = new Date(Date.now() + duration);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -135,8 +135,8 @@ categoryController.get = function (req, res, callback) {
|
|||||||
|
|
||||||
addTags(categoryData, res);
|
addTags(categoryData, res);
|
||||||
|
|
||||||
categoryData['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
|
categoryData['feeds:disableRSS'] = meta.config['feeds:disableRSS'];
|
||||||
categoryData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
|
categoryData['reputation:disabled'] = meta.config['reputation:disabled'];
|
||||||
categoryData.title = translator.escape(categoryData.name);
|
categoryData.title = translator.escape(categoryData.name);
|
||||||
pageCount = Math.max(1, Math.ceil(categoryData.topic_count / settings.topicsPerPage));
|
pageCount = Math.max(1, Math.ceil(categoryData.topic_count / settings.topicsPerPage));
|
||||||
categoryData.pagination = pagination.create(currentPage, pageCount, req.query);
|
categoryData.pagination = pagination.create(currentPage, pageCount, req.query);
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ groupsController.getGroupsFromSet = function (uid, sort, start, stop, callback)
|
|||||||
function (groupsData, next) {
|
function (groupsData, next) {
|
||||||
next(null, {
|
next(null, {
|
||||||
groups: groupsData,
|
groups: groupsData,
|
||||||
allowGroupCreation: parseInt(meta.config.allowGroupCreation, 10) === 1,
|
allowGroupCreation: meta.config.allowGroupCreation,
|
||||||
nextStart: stop + 1,
|
nextStart: stop + 1,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -106,7 +106,7 @@ groupsController.details = function (req, res, callback) {
|
|||||||
results.group.isOwner = results.group.isOwner || results.isAdmin || (results.isGlobalMod && !results.group.system);
|
results.group.isOwner = results.group.isOwner || results.isAdmin || (results.isGlobalMod && !results.group.system);
|
||||||
results.title = '[[pages:group, ' + results.group.displayName + ']]';
|
results.title = '[[pages:group, ' + results.group.displayName + ']]';
|
||||||
results.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[pages:groups]]', url: '/groups' }, { text: results.group.displayName }]);
|
results.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[pages:groups]]', url: '/groups' }, { text: results.group.displayName }]);
|
||||||
results.allowPrivateGroups = parseInt(meta.config.allowPrivateGroups, 10) === 1;
|
results.allowPrivateGroups = meta.config.allowPrivateGroups;
|
||||||
|
|
||||||
res.render('groups/details', results);
|
res.render('groups/details', results);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ function rewrite(req, res, next) {
|
|||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
if (parseInt(meta.config.allowUserHomePage, 10)) {
|
if (meta.config.allowUserHomePage) {
|
||||||
getUserHomeRoute(req.uid, next);
|
getUserHomeRoute(req.uid, next);
|
||||||
} else {
|
} else {
|
||||||
next(null, adminHomePageRoute());
|
next(null, adminHomePageRoute());
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ Controllers.reset = function (req, res, next) {
|
|||||||
valid: valid,
|
valid: valid,
|
||||||
displayExpiryNotice: req.session.passwordExpired,
|
displayExpiryNotice: req.session.passwordExpired,
|
||||||
code: code,
|
code: code,
|
||||||
minimumPasswordLength: parseInt(meta.config.minimumPasswordLength, 10),
|
minimumPasswordLength: meta.config.minimumPasswordLength,
|
||||||
minimumPasswordStrength: parseInt(meta.config.minimumPasswordStrength, 10),
|
minimumPasswordStrength: meta.config.minimumPasswordStrength,
|
||||||
breadcrumbs: helpers.buildBreadcrumbs([
|
breadcrumbs: helpers.buildBreadcrumbs([
|
||||||
{
|
{
|
||||||
text: '[[reset_password:reset_password]]',
|
text: '[[reset_password:reset_password]]',
|
||||||
@@ -180,10 +180,10 @@ Controllers.register = function (req, res, next) {
|
|||||||
|
|
||||||
data.authentication = loginStrategies;
|
data.authentication = loginStrategies;
|
||||||
|
|
||||||
data.minimumUsernameLength = parseInt(meta.config.minimumUsernameLength, 10);
|
data.minimumUsernameLength = meta.config.minimumUsernameLength;
|
||||||
data.maximumUsernameLength = parseInt(meta.config.maximumUsernameLength, 10);
|
data.maximumUsernameLength = meta.config.maximumUsernameLength;
|
||||||
data.minimumPasswordLength = parseInt(meta.config.minimumPasswordLength, 10);
|
data.minimumPasswordLength = meta.config.minimumPasswordLength;
|
||||||
data.minimumPasswordStrength = parseInt(meta.config.minimumPasswordStrength || 1, 10);
|
data.minimumPasswordStrength = meta.config.minimumPasswordStrength;
|
||||||
data.termsOfUse = termsOfUse.postData.content;
|
data.termsOfUse = termsOfUse.postData.content;
|
||||||
data.breadcrumbs = helpers.buildBreadcrumbs([{
|
data.breadcrumbs = helpers.buildBreadcrumbs([{
|
||||||
text: '[[register:register]]',
|
text: '[[register:register]]',
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ recentController.getData = function (req, url, sort, callback) {
|
|||||||
data.selectedCategory = categoryData.selectedCategory;
|
data.selectedCategory = categoryData.selectedCategory;
|
||||||
data.selectedCids = categoryData.selectedCids;
|
data.selectedCids = categoryData.selectedCids;
|
||||||
data.nextStart = stop + 1;
|
data.nextStart = stop + 1;
|
||||||
data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
|
data['feeds:disableRSS'] = meta.config['feeds:disableRSS'];
|
||||||
data.rssFeedUrl = nconf.get('relative_path') + '/' + url + '.rss';
|
data.rssFeedUrl = nconf.get('relative_path') + '/' + url + '.rss';
|
||||||
if (req.loggedIn) {
|
if (req.loggedIn) {
|
||||||
data.rssFeedUrl += '?uid=' + req.uid + '&token=' + rssToken;
|
data.rssFeedUrl += '?uid=' + req.uid + '&token=' + rssToken;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ sitemapController.getTopicPage = function (req, res, next) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function sendSitemap(method, res, callback) {
|
function sendSitemap(method, res, callback) {
|
||||||
if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) {
|
if (meta.config['feeds:disableSitemap']) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
|||||||
@@ -138,15 +138,15 @@ topicsController.get = function (req, res, callback) {
|
|||||||
},
|
},
|
||||||
function (topicData) {
|
function (topicData) {
|
||||||
topicData.privileges = userPrivileges;
|
topicData.privileges = userPrivileges;
|
||||||
topicData.topicStaleDays = parseInt(meta.config.topicStaleDays, 10) || 60;
|
topicData.topicStaleDays = meta.config.topicStaleDays;
|
||||||
topicData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
|
topicData['reputation:disabled'] = meta.config['reputation:disabled'];
|
||||||
topicData['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1;
|
topicData['downvote:disabled'] = meta.config['downvote:disabled'];
|
||||||
topicData['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
|
topicData['feeds:disableRSS'] = meta.config['feeds:disableRSS'];
|
||||||
topicData.bookmarkThreshold = parseInt(meta.config.bookmarkThreshold, 10) || 5;
|
topicData.bookmarkThreshold = meta.config.bookmarkThreshold;
|
||||||
topicData.postEditDuration = parseInt(meta.config.postEditDuration, 10) || 0;
|
topicData.postEditDuration = meta.config.postEditDuration;
|
||||||
topicData.postDeleteDuration = parseInt(meta.config.postDeleteDuration, 10) || 0;
|
topicData.postDeleteDuration = meta.config.postDeleteDuration;
|
||||||
topicData.scrollToMyPost = settings.scrollToMyPost;
|
topicData.scrollToMyPost = settings.scrollToMyPost;
|
||||||
topicData.allowMultipleBadges = parseInt(meta.config.allowMultipleBadges, 10) === 1;
|
topicData.allowMultipleBadges = meta.config.allowMultipleBadges === 1;
|
||||||
topicData.rssFeedUrl = nconf.get('relative_path') + '/topic/' + topicData.tid + '.rss';
|
topicData.rssFeedUrl = nconf.get('relative_path') + '/topic/' + topicData.tid + '.rss';
|
||||||
if (req.loggedIn) {
|
if (req.loggedIn) {
|
||||||
topicData.rssFeedUrl += '?uid=' + req.uid + '&token=' + rssToken;
|
topicData.rssFeedUrl += '?uid=' + req.uid + '&token=' + rssToken;
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ function uploadAsImage(req, uploadedFile, callback) {
|
|||||||
uploadsController.uploadFile(req.uid, uploadedFile, next);
|
uploadsController.uploadFile(req.uid, uploadedFile, next);
|
||||||
},
|
},
|
||||||
function (fileObj, next) {
|
function (fileObj, next) {
|
||||||
if (parseInt(meta.config.maximumImageWidth, 10) === 0) {
|
if (meta.config.maximumImageWidth === 0) {
|
||||||
return next(null, fileObj);
|
return next(null, fileObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ function uploadAsFile(req, uploadedFile, callback) {
|
|||||||
if (!canUpload) {
|
if (!canUpload) {
|
||||||
return next(new Error('[[error:no-privileges]]'));
|
return next(new Error('[[error:no-privileges]]'));
|
||||||
}
|
}
|
||||||
if (parseInt(meta.config.allowFileUploads, 10) !== 1) {
|
if (!meta.config.allowFileUploads) {
|
||||||
return next(new Error('[[error:uploads-are-disabled]]'));
|
return next(new Error('[[error:uploads-are-disabled]]'));
|
||||||
}
|
}
|
||||||
uploadsController.uploadFile(req.uid, uploadedFile, next);
|
uploadsController.uploadFile(req.uid, uploadedFile, next);
|
||||||
@@ -112,15 +112,15 @@ function resizeImage(fileObj, callback) {
|
|||||||
image.size(fileObj.path, next);
|
image.size(fileObj.path, next);
|
||||||
},
|
},
|
||||||
function (imageData, next) {
|
function (imageData, next) {
|
||||||
if (imageData.width < (parseInt(meta.config.maximumImageWidth, 10) || 760)) {
|
if (imageData.width < meta.config.maximumImageWidth) {
|
||||||
return callback(null, fileObj);
|
return callback(null, fileObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
image.resizeImage({
|
image.resizeImage({
|
||||||
path: fileObj.path,
|
path: fileObj.path,
|
||||||
target: file.appendToFileName(fileObj.path, '-resized'),
|
target: file.appendToFileName(fileObj.path, '-resized'),
|
||||||
width: parseInt(meta.config.maximumImageWidth, 10) || 760,
|
width: meta.config.maximumImageWidth,
|
||||||
quality: parseInt(meta.config.resizeImageQuality, 10) || 60,
|
quality: meta.config.resizeImageQuality,
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -133,7 +133,7 @@ function resizeImage(fileObj, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uploadsController.uploadThumb = function (req, res, next) {
|
uploadsController.uploadThumb = function (req, res, next) {
|
||||||
if (parseInt(meta.config.allowTopicsThumbnail, 10) !== 1) {
|
if (!meta.config.allowTopicsThumbnail) {
|
||||||
deleteTempFiles(req.files.files);
|
deleteTempFiles(req.files.files);
|
||||||
return next(new Error('[[error:topic-thumbnails-are-disabled]]'));
|
return next(new Error('[[error:topic-thumbnails-are-disabled]]'));
|
||||||
}
|
}
|
||||||
@@ -148,11 +148,10 @@ uploadsController.uploadThumb = function (req, res, next) {
|
|||||||
file.isFileTypeAllowed(uploadedFile.path, next);
|
file.isFileTypeAllowed(uploadedFile.path, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
var size = parseInt(meta.config.topicThumbSize, 10) || 120;
|
|
||||||
image.resizeImage({
|
image.resizeImage({
|
||||||
path: uploadedFile.path,
|
path: uploadedFile.path,
|
||||||
width: size,
|
width: meta.config.topicThumbSize,
|
||||||
height: size,
|
height: meta.config.topicThumbSize,
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -206,7 +205,7 @@ uploadsController.uploadFile = function (uid, uploadedFile, callback) {
|
|||||||
return callback(new Error('[[error:invalid-file]]'));
|
return callback(new Error('[[error:invalid-file]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uploadedFile.size > parseInt(meta.config.maximumFileSize, 10) * 1024) {
|
if (uploadedFile.size > meta.config.maximumFileSize * 1024) {
|
||||||
return callback(new Error('[[error:file-too-big, ' + meta.config.maximumFileSize + ']]'));
|
return callback(new Error('[[error:file-too-big, ' + meta.config.maximumFileSize + ']]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ userController.getUserDataByField = function (callerUid, field, fieldValue, call
|
|||||||
};
|
};
|
||||||
|
|
||||||
userController.getUserDataByUID = function (callerUid, uid, callback) {
|
userController.getUserDataByUID = function (callerUid, uid, callback) {
|
||||||
if (!parseInt(callerUid, 10) && parseInt(meta.config.privateUserInfo, 10) === 1) {
|
if (!parseInt(callerUid, 10) && meta.config.privateUserInfo) {
|
||||||
return callback(new Error('[[error:no-privileges]]'));
|
return callback(new Error('[[error:no-privileges]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,8 +100,8 @@ userController.getUserDataByUID = function (callerUid, uid, callback) {
|
|||||||
return callback(err || new Error('[[error:no-user]]'));
|
return callback(err || new Error('[[error:no-user]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
results.userData.email = results.settings.showemail && parseInt(meta.config.hideEmail, 10) !== 1 ? results.userData.email : undefined;
|
results.userData.email = results.settings.showemail && !meta.config.hideEmail ? results.userData.email : undefined;
|
||||||
results.userData.fullname = results.settings.showfullname && parseInt(meta.config.hideFullname, 10) !== 1 ? results.userData.fullname : undefined;
|
results.userData.fullname = results.settings.showfullname && !meta.config.hideFullname ? results.userData.fullname : undefined;
|
||||||
|
|
||||||
callback(null, results.userData);
|
callback(null, results.userData);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ usersController.getUsersSortedByPosts = function (req, res, next) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
usersController.getUsersSortedByReputation = function (req, res, next) {
|
usersController.getUsersSortedByReputation = function (req, res, next) {
|
||||||
if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
|
if (meta.config['reputation:disabled']) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
usersController.renderUsersPage('users:reputation', req, res, next);
|
usersController.renderUsersPage('users:reputation', req, res, next);
|
||||||
@@ -169,7 +169,7 @@ usersController.getUsers = function (set, uid, query, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var page = parseInt(query.page, 10) || 1;
|
var page = parseInt(query.page, 10) || 1;
|
||||||
var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 50;
|
var resultsPerPage = meta.config.userSearchResultsPerPage;
|
||||||
var start = Math.max(0, page - 1) * resultsPerPage;
|
var start = Math.max(0, page - 1) * resultsPerPage;
|
||||||
var stop = start + resultsPerPage - 1;
|
var stop = start + resultsPerPage - 1;
|
||||||
|
|
||||||
@@ -241,7 +241,7 @@ function render(req, res, data, next) {
|
|||||||
data.maximumInvites = meta.config.maximumInvites;
|
data.maximumInvites = meta.config.maximumInvites;
|
||||||
data.inviteOnly = registrationType === 'invite-only' || registrationType === 'admin-invite-only';
|
data.inviteOnly = registrationType === 'invite-only' || registrationType === 'admin-invite-only';
|
||||||
data.adminInviteOnly = registrationType === 'admin-invite-only';
|
data.adminInviteOnly = registrationType === 'admin-invite-only';
|
||||||
data['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
|
data['reputation:disabled'] = meta.config['reputation:disabled'];
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
|
|||||||
@@ -257,9 +257,8 @@ Flags.validate = function (payload, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var minimumReputation = utils.isNumber(meta.config['min:rep:flag']) ? parseInt(meta.config['min:rep:flag'], 10) : 0;
|
|
||||||
// Check if reporter meets rep threshold (or can edit the target post, in which case threshold does not apply)
|
// Check if reporter meets rep threshold (or can edit the target post, in which case threshold does not apply)
|
||||||
if (!editable.flag && parseInt(data.reporter.reputation, 10) < minimumReputation) {
|
if (!editable.flag && data.reporter.reputation < meta.config['min:rep:flag']) {
|
||||||
return callback(new Error('[[error:not-enough-reputation-to-flag]]'));
|
return callback(new Error('[[error:not-enough-reputation-to-flag]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,9 +272,8 @@ Flags.validate = function (payload, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var minimumReputation = utils.isNumber(meta.config['min:rep:flag']) ? parseInt(meta.config['min:rep:flag'], 10) : 0;
|
|
||||||
// Check if reporter meets rep threshold (or can edit the target user, in which case threshold does not apply)
|
// Check if reporter meets rep threshold (or can edit the target user, in which case threshold does not apply)
|
||||||
if (!editable && parseInt(data.reporter.reputation, 10) < minimumReputation) {
|
if (!editable && data.reporter.reputation < meta.config['min:rep:flag']) {
|
||||||
return callback(new Error('[[error:not-enough-reputation-to-flag]]'));
|
return callback(new Error('[[error:not-enough-reputation-to-flag]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ module.exports = function (Groups) {
|
|||||||
return callback(new Error('[[error:group-name-too-short]]'));
|
return callback(new Error('[[error:group-name-too-short]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Groups.isPrivilegeGroup(name) && name.length > (parseInt(meta.config.maximumGroupNameLength, 10) || 255)) {
|
if (!Groups.isPrivilegeGroup(name) && name.length > meta.config.maximumGroupNameLength) {
|
||||||
return callback(new Error('[[error:group-name-too-long]]'));
|
return callback(new Error('[[error:group-name-too-long]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,8 +93,8 @@ image.checkDimensions = function (path, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxWidth = parseInt(meta.config.rejectImageWidth, 10) || 5000;
|
const maxWidth = meta.config.rejectImageWidth;
|
||||||
const maxHeight = parseInt(meta.config.rejectImageHeight, 10) || 5000;
|
const maxHeight = meta.config.rejectImageHeight;
|
||||||
if (result.width > maxWidth || result.height > maxHeight) {
|
if (result.width > maxWidth || result.height > maxHeight) {
|
||||||
return callback(new Error('[[error:invalid-image-dimensions]]'));
|
return callback(new Error('[[error:invalid-image-dimensions]]'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ Messaging.getTeaser = function (uid, roomId, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Messaging.canMessageUser = function (uid, toUid, callback) {
|
Messaging.canMessageUser = function (uid, toUid, callback) {
|
||||||
if (parseInt(meta.config.disableChat, 10) === 1 || !uid || uid === toUid) {
|
if (meta.config.disableChat || !uid || uid === toUid) {
|
||||||
return callback(new Error('[[error:chat-disabled]]'));
|
return callback(new Error('[[error:chat-disabled]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +272,7 @@ Messaging.canMessageUser = function (uid, toUid, callback) {
|
|||||||
return callback(new Error('[[error:user-banned]]'));
|
return callback(new Error('[[error:user-banned]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) {
|
if (meta.config.requireEmailConfirmation && parseInt(userData['email:confirmed'], 10) !== 1) {
|
||||||
return callback(new Error('[[error:email-not-confirmed-chat]]'));
|
return callback(new Error('[[error:email-not-confirmed-chat]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,7 +299,7 @@ Messaging.canMessageUser = function (uid, toUid, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Messaging.canMessageRoom = function (uid, roomId, callback) {
|
Messaging.canMessageRoom = function (uid, roomId, callback) {
|
||||||
if (parseInt(meta.config.disableChat, 10) === 1 || !uid) {
|
if (meta.config.disableChat || !uid) {
|
||||||
return callback(new Error('[[error:chat-disabled]]'));
|
return callback(new Error('[[error:chat-disabled]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,7 +326,7 @@ Messaging.canMessageRoom = function (uid, roomId, callback) {
|
|||||||
return next(new Error('[[error:user-banned]]'));
|
return next(new Error('[[error:user-banned]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) {
|
if (meta.config.requireEmailConfirmation && parseInt(userData['email:confirmed'], 10) !== 1) {
|
||||||
return next(new Error('[[error:email-not-confirmed-chat]]'));
|
return next(new Error('[[error:email-not-confirmed-chat]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,9 +59,9 @@ module.exports = function (Messaging) {
|
|||||||
durationConfig = 'chatDeleteDuration';
|
durationConfig = 'chatDeleteDuration';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(meta.config.disableChat, 10) === 1) {
|
if (meta.config.disableChat) {
|
||||||
return callback(new Error('[[error:chat-disabled]]'));
|
return callback(new Error('[[error:chat-disabled]]'));
|
||||||
} else if (parseInt(meta.config.disableChatMessageEditing, 10) === 1) {
|
} else if (meta.config.disableChatMessageEditing) {
|
||||||
return callback(new Error('[[error:chat-message-editing-disabled]]'));
|
return callback(new Error('[[error:chat-message-editing-disabled]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ module.exports = function (Messaging) {
|
|||||||
return callback(new Error('[[error:user-banned]]'));
|
return callback(new Error('[[error:user-banned]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) {
|
if (meta.config.requireEmailConfirmation && parseInt(userData['email:confirmed'], 10) !== 1) {
|
||||||
return callback(new Error('[[error:email-not-confirmed]]'));
|
return callback(new Error('[[error:email-not-confirmed]]'));
|
||||||
}
|
}
|
||||||
async.parallel({
|
async.parallel({
|
||||||
@@ -90,7 +90,7 @@ module.exports = function (Messaging) {
|
|||||||
if (results.isAdmin) {
|
if (results.isAdmin) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
var chatConfigDuration = parseInt(meta.config[durationConfig], 10);
|
var chatConfigDuration = meta.config[durationConfig];
|
||||||
if (chatConfigDuration && Date.now() - parseInt(results.messageData.timestamp, 10) > chatConfigDuration * 1000) {
|
if (chatConfigDuration && Date.now() - parseInt(results.messageData.timestamp, 10) > chatConfigDuration * 1000) {
|
||||||
return callback(new Error('[[error:chat-' + type + '-duration-expired, ' + meta.config[durationConfig] + ']]'));
|
return callback(new Error('[[error:chat-' + type + '-duration-expired, ' + meta.config[durationConfig] + ']]'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -321,8 +321,8 @@ module.exports = function (Messaging) {
|
|||||||
room.canReply = results.canReply;
|
room.canReply = results.canReply;
|
||||||
room.groupChat = room.hasOwnProperty('groupChat') ? room.groupChat : results.users.length > 2;
|
room.groupChat = room.hasOwnProperty('groupChat') ? room.groupChat : results.users.length > 2;
|
||||||
room.usernames = Messaging.generateUsernames(results.users, uid);
|
room.usernames = Messaging.generateUsernames(results.users, uid);
|
||||||
room.maximumUsersInChatRoom = parseInt(meta.config.maximumUsersInChatRoom, 10) || 0;
|
room.maximumUsersInChatRoom = meta.config.maximumUsersInChatRoom;
|
||||||
room.maximumChatMessageLength = parseInt(meta.config.maximumChatMessageLength, 10) || 1000;
|
room.maximumChatMessageLength = meta.config.maximumChatMessageLength;
|
||||||
room.showUserInput = !room.maximumUsersInChatRoom || room.maximumUsersInChatRoom > 2;
|
room.showUserInput = !room.maximumUsersInChatRoom || room.maximumUsersInChatRoom > 2;
|
||||||
room.isAdminOrGlobalMod = results.isAdminOrGlobalMod;
|
room.isAdminOrGlobalMod = results.isAdminOrGlobalMod;
|
||||||
next(null, room);
|
next(null, room);
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ function restart() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Meta.getSessionTTLSeconds = function () {
|
Meta.getSessionTTLSeconds = function () {
|
||||||
var ttlDays = 60 * 60 * 24 * (parseInt(Meta.config.loginDays, 10) || 0);
|
var ttlDays = 60 * 60 * 24 * Meta.config.loginDays;
|
||||||
var ttlSeconds = (parseInt(Meta.config.loginSeconds, 10) || 0);
|
var ttlSeconds = Meta.config.loginSeconds;
|
||||||
var ttl = ttlSeconds || ttlDays || 1209600; // Default to 14 days
|
var ttl = ttlSeconds || ttlDays || 1209600; // Default to 14 days
|
||||||
return ttl;
|
return ttl;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,11 +10,34 @@ var db = require('../database');
|
|||||||
var pubsub = require('../pubsub');
|
var pubsub = require('../pubsub');
|
||||||
var Meta = require('../meta');
|
var Meta = require('../meta');
|
||||||
var cacheBuster = require('./cacheBuster');
|
var cacheBuster = require('./cacheBuster');
|
||||||
|
const defaults = require('../../install/data/defaults');
|
||||||
|
|
||||||
var Configs = module.exports;
|
var Configs = module.exports;
|
||||||
|
|
||||||
Meta.config = {};
|
Meta.config = {};
|
||||||
|
|
||||||
|
function deserialize(config) {
|
||||||
|
var deserialized = {};
|
||||||
|
Object.keys(config).forEach(function (key) {
|
||||||
|
if (typeof config[key] !== 'string') {
|
||||||
|
deserialized[key] = config[key];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var number = parseFloat(config[key]);
|
||||||
|
if (!isNaN(number) && isFinite(config[key])) {
|
||||||
|
deserialized[key] = number;
|
||||||
|
} else if (config[key] === 'true') {
|
||||||
|
deserialized[key] = true;
|
||||||
|
} else if (config[key] === 'false') {
|
||||||
|
deserialized[key] = false;
|
||||||
|
} else {
|
||||||
|
deserialized[key] = config[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return deserialized;
|
||||||
|
}
|
||||||
|
|
||||||
Configs.init = function (callback) {
|
Configs.init = function (callback) {
|
||||||
var config;
|
var config;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -34,20 +57,37 @@ Configs.init = function (callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Configs.list = function (callback) {
|
Configs.list = function (callback) {
|
||||||
db.getObject('config', function (err, config) {
|
Configs.getFields([], callback);
|
||||||
config = config || {};
|
|
||||||
config.version = nconf.get('version');
|
|
||||||
config.registry = nconf.get('registry');
|
|
||||||
callback(err, config);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Configs.get = function (field, callback) {
|
Configs.get = function (field, callback) {
|
||||||
db.getObjectField('config', field, callback);
|
Configs.getFields([field], function (err, values) {
|
||||||
|
callback(err, values ? values[field] : null);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Configs.getFields = function (fields, callback) {
|
Configs.getFields = function (fields, callback) {
|
||||||
db.getObjectFields('config', fields, callback);
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
if (fields.length) {
|
||||||
|
db.getObjectFields('config', fields, next);
|
||||||
|
} else {
|
||||||
|
db.getObject('config', next);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function (values, next) {
|
||||||
|
try {
|
||||||
|
values = Object.assign({}, defaults, values ? deserialize(values) : {});
|
||||||
|
} catch (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
if (!fields.length) {
|
||||||
|
values.version = nconf.get('version');
|
||||||
|
values.registry = nconf.get('registry');
|
||||||
|
}
|
||||||
|
next(null, values);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Configs.set = function (field, value, callback) {
|
Configs.set = function (field, value, callback) {
|
||||||
@@ -56,13 +96,15 @@ Configs.set = function (field, value, callback) {
|
|||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = {};
|
Configs.setMultiple({
|
||||||
data[field] = value;
|
[field]: value,
|
||||||
Configs.setMultiple(data, callback);
|
}, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// data comes from client-side
|
||||||
Configs.setMultiple = function (data, callback) {
|
Configs.setMultiple = function (data, callback) {
|
||||||
|
data = deserialize(data);
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
processConfig(data, next);
|
processConfig(data, next);
|
||||||
@@ -77,6 +119,22 @@ Configs.setMultiple = function (data, callback) {
|
|||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Configs.setOnEmpty = function (values, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
db.getObject('config', next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
var config = Object.assign({}, values, data ? deserialize(data) : {});
|
||||||
|
db.setObject('config', config, next);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
Configs.remove = function (field, callback) {
|
||||||
|
db.deleteObjectField('config', field, callback);
|
||||||
|
};
|
||||||
|
|
||||||
function processConfig(data, callback) {
|
function processConfig(data, callback) {
|
||||||
async.parallel([
|
async.parallel([
|
||||||
async.apply(saveRenderedCss, data),
|
async.apply(saveRenderedCss, data),
|
||||||
@@ -141,29 +199,3 @@ pubsub.on('config:update', function onConfigReceived(config) {
|
|||||||
updateLocalConfig(config);
|
updateLocalConfig(config);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Configs.setOnEmpty = function (values, callback) {
|
|
||||||
async.waterfall([
|
|
||||||
function (next) {
|
|
||||||
db.getObject('config', next);
|
|
||||||
},
|
|
||||||
function (data, next) {
|
|
||||||
data = data || {};
|
|
||||||
var empty = {};
|
|
||||||
Object.keys(values).forEach(function (key) {
|
|
||||||
if (!data.hasOwnProperty(key)) {
|
|
||||||
empty[key] = values[key];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (Object.keys(empty).length) {
|
|
||||||
db.setObject('config', empty, next);
|
|
||||||
} else {
|
|
||||||
setImmediate(next);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
Configs.remove = function (field, callback) {
|
|
||||||
db.deleteObjectField('config', field, callback);
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ Themes.setupPaths = function (callback) {
|
|||||||
async.parallel({
|
async.parallel({
|
||||||
themesData: Themes.get,
|
themesData: Themes.get,
|
||||||
currentThemeId: function (next) {
|
currentThemeId: function (next) {
|
||||||
db.getObjectField('config', 'theme:id', next);
|
Meta.configs.get('theme:id', next);
|
||||||
},
|
},
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -183,19 +183,19 @@ module.exports = function (middleware) {
|
|||||||
templateValues.isAdmin = results.user.isAdmin;
|
templateValues.isAdmin = results.user.isAdmin;
|
||||||
templateValues.isGlobalMod = results.user.isGlobalMod;
|
templateValues.isGlobalMod = results.user.isGlobalMod;
|
||||||
templateValues.showModMenu = results.user.isAdmin || results.user.isGlobalMod || results.user.isMod;
|
templateValues.showModMenu = results.user.isAdmin || results.user.isGlobalMod || results.user.isMod;
|
||||||
templateValues.canChat = results.canChat && parseInt(meta.config.disableChat, 10) !== 1;
|
templateValues.canChat = results.canChat && meta.config.disableChat !== 1;
|
||||||
templateValues.user = results.user;
|
templateValues.user = results.user;
|
||||||
templateValues.userJSON = jsesc(JSON.stringify(results.user), { isScriptContext: true });
|
templateValues.userJSON = jsesc(JSON.stringify(results.user), { isScriptContext: true });
|
||||||
templateValues.useCustomCSS = parseInt(meta.config.useCustomCSS, 10) === 1 && meta.config.customCSS;
|
templateValues.useCustomCSS = meta.config.useCustomCSS && meta.config.customCSS;
|
||||||
templateValues.customCSS = templateValues.useCustomCSS ? (meta.config.renderedCustomCSS || '') : '';
|
templateValues.customCSS = templateValues.useCustomCSS ? (meta.config.renderedCustomCSS || '') : '';
|
||||||
templateValues.useCustomHTML = parseInt(meta.config.useCustomHTML, 10) === 1;
|
templateValues.useCustomHTML = meta.config.useCustomHTML;
|
||||||
templateValues.customHTML = templateValues.useCustomHTML ? meta.config.customHTML : '';
|
templateValues.customHTML = templateValues.useCustomHTML ? meta.config.customHTML : '';
|
||||||
templateValues.maintenanceHeader = parseInt(meta.config.maintenanceMode, 10) === 1 && !results.isAdmin;
|
templateValues.maintenanceHeader = meta.config.maintenanceMode && !results.isAdmin;
|
||||||
templateValues.defaultLang = meta.config.defaultLang || 'en-GB';
|
templateValues.defaultLang = meta.config.defaultLang || 'en-GB';
|
||||||
templateValues.userLang = res.locals.config.userLang;
|
templateValues.userLang = res.locals.config.userLang;
|
||||||
templateValues.languageDirection = results.languageDirection;
|
templateValues.languageDirection = results.languageDirection;
|
||||||
templateValues.privateUserInfo = parseInt(meta.config.privateUserInfo, 10) === 1;
|
templateValues.privateUserInfo = meta.config.privateUserInfo;
|
||||||
templateValues.privateTagListing = parseInt(meta.config.privateTagListing, 10) === 1;
|
templateValues.privateTagListing = meta.config.privateTagListing;
|
||||||
|
|
||||||
templateValues.template = { name: res.locals.template };
|
templateValues.template = { name: res.locals.template };
|
||||||
templateValues.template[res.locals.template] = true;
|
templateValues.template[res.locals.template] = true;
|
||||||
@@ -243,7 +243,7 @@ module.exports = function (middleware) {
|
|||||||
});
|
});
|
||||||
addTimeagoLocaleScript(data.templateValues.scripts, res.locals.config.userLang);
|
addTimeagoLocaleScript(data.templateValues.scripts, res.locals.config.userLang);
|
||||||
|
|
||||||
data.templateValues.useCustomJS = parseInt(meta.config.useCustomJS, 10) === 1;
|
data.templateValues.useCustomJS = meta.config.useCustomJS;
|
||||||
data.templateValues.customJS = data.templateValues.useCustomJS ? meta.config.customJS : '';
|
data.templateValues.customJS = data.templateValues.useCustomJS ? meta.config.customJS : '';
|
||||||
data.templateValues.isSpider = req.isSpider();
|
data.templateValues.isSpider = req.isSpider();
|
||||||
req.app.render('footer', data.templateValues, next);
|
req.app.render('footer', data.templateValues, next);
|
||||||
@@ -270,7 +270,7 @@ module.exports = function (middleware) {
|
|||||||
if (config && config.bootswatchSkin !== 'noskin') {
|
if (config && config.bootswatchSkin !== 'noskin') {
|
||||||
var skinToUse = '';
|
var skinToUse = '';
|
||||||
|
|
||||||
if (parseInt(meta.config.disableCustomUserSkins, 10) !== 1) {
|
if (!meta.config.disableCustomUserSkins) {
|
||||||
skinToUse = config.bootswatchSkin;
|
skinToUse = config.bootswatchSkin;
|
||||||
} else if (meta.config.bootswatchSkin) {
|
} else if (meta.config.bootswatchSkin) {
|
||||||
skinToUse = meta.config.bootswatchSkin;
|
skinToUse = meta.config.bootswatchSkin;
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ middleware.routeTouchIcon = function (req, res) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
middleware.privateTagListing = function (req, res, next) {
|
middleware.privateTagListing = function (req, res, next) {
|
||||||
if (!req.loggedIn && parseInt(meta.config.privateTagListing, 10) === 1) {
|
if (!req.loggedIn && meta.config.privateTagListing) {
|
||||||
controllers.helpers.notAllowed(req, res);
|
controllers.helpers.notAllowed(req, res);
|
||||||
} else {
|
} else {
|
||||||
next();
|
next();
|
||||||
@@ -140,7 +140,7 @@ function expose(exposedField, method, field, req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
middleware.privateUploads = function (req, res, next) {
|
middleware.privateUploads = function (req, res, next) {
|
||||||
if (req.loggedIn || parseInt(meta.config.privateUploads, 10) !== 1) {
|
if (req.loggedIn || !meta.config.privateUploads) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ middleware.privateUploads = function (req, res, next) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
middleware.busyCheck = function (req, res, next) {
|
middleware.busyCheck = function (req, res, next) {
|
||||||
if (global.env === 'production' && (!meta.config.hasOwnProperty('eventLoopCheckEnabled') || parseInt(meta.config.eventLoopCheckEnabled, 10) === 1) && toobusy()) {
|
if (global.env === 'production' && (!meta.config.hasOwnProperty('eventLoopCheckEnabled') || meta.config.eventLoopCheckEnabled) && toobusy()) {
|
||||||
analytics.increment('errors:503');
|
analytics.increment('errors:503');
|
||||||
res.status(503).type('text/html').sendFile(path.join(__dirname, '../../public/503.html'));
|
res.status(503).type('text/html').sendFile(path.join(__dirname, '../../public/503.html'));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ var user = require('../user');
|
|||||||
|
|
||||||
module.exports = function (middleware) {
|
module.exports = function (middleware) {
|
||||||
middleware.maintenanceMode = function (req, res, callback) {
|
middleware.maintenanceMode = function (req, res, callback) {
|
||||||
if (parseInt(meta.config.maintenanceMode, 10) !== 1) {
|
if (!meta.config.maintenanceMode) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
var url = req.url.replace(nconf.get('relative_path'), '');
|
var url = req.url.replace(nconf.get('relative_path'), '');
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ module.exports = function (middleware) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
middleware.checkGlobalPrivacySettings = function (req, res, next) {
|
middleware.checkGlobalPrivacySettings = function (req, res, next) {
|
||||||
if (!req.loggedIn && !!parseInt(meta.config.privateUserInfo, 10)) {
|
if (!req.loggedIn && meta.config.privateUserInfo) {
|
||||||
return middleware.authenticate(req, res, next);
|
return middleware.authenticate(req, res, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,8 +187,8 @@ module.exports = function (middleware) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var loginTime = req.session.meta ? req.session.meta.datetime : 0;
|
var loginTime = req.session.meta ? req.session.meta.datetime : 0;
|
||||||
var adminReloginDuration = (meta.config.adminReloginDuration || 60) * 60000;
|
var adminReloginDuration = meta.config.adminReloginDuration * 60000;
|
||||||
var disabled = parseInt(meta.config.adminReloginDuration, 10) === 0;
|
var disabled = meta.config.adminReloginDuration === 0;
|
||||||
if (disabled || (loginTime && parseInt(loginTime, 10) > Date.now() - adminReloginDuration)) {
|
if (disabled || (loginTime && parseInt(loginTime, 10) > Date.now() - adminReloginDuration)) {
|
||||||
var timeLeft = parseInt(loginTime, 10) - (Date.now() - adminReloginDuration);
|
var timeLeft = parseInt(loginTime, 10) - (Date.now() - adminReloginDuration);
|
||||||
if (req.session.meta && timeLeft < Math.min(300000, adminReloginDuration)) {
|
if (req.session.meta && timeLeft < Math.min(300000, adminReloginDuration)) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ var LRU = require('lru-cache');
|
|||||||
var meta = require('../meta');
|
var meta = require('../meta');
|
||||||
|
|
||||||
var cache = LRU({
|
var cache = LRU({
|
||||||
max: parseInt(meta.config.postCacheSize, 10) || 5242880,
|
max: meta.config.postCacheSize,
|
||||||
length: function (n) { return n.length; },
|
length: function (n) { return n.length; },
|
||||||
maxAge: 0,
|
maxAge: 0,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ module.exports = function (Posts) {
|
|||||||
postData.toPid = data.toPid;
|
postData.toPid = data.toPid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.ip && parseInt(meta.config.trackIpPerPost, 10) === 1) {
|
if (data.ip && meta.config.trackIpPerPost) {
|
||||||
postData.ip = data.ip;
|
postData.ip = data.ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ var async = require('async');
|
|||||||
var db = require('../database');
|
var db = require('../database');
|
||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
|
|
||||||
const intFields = ['uid', 'pid', 'tid', 'deleted'];
|
const intFields = ['uid', 'pid', 'tid', 'deleted', 'timestamp'];
|
||||||
|
|
||||||
module.exports = function (Posts) {
|
module.exports = function (Posts) {
|
||||||
Posts.getPostsFields = function (pids, fields, callback) {
|
Posts.getPostsFields = function (pids, fields, callback) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ var translator = require('../translator');
|
|||||||
var Diffs = {};
|
var Diffs = {};
|
||||||
|
|
||||||
Diffs.exists = function (pid, callback) {
|
Diffs.exists = function (pid, callback) {
|
||||||
if (parseInt(meta.config.enablePostHistory || 1, 10) !== 1) {
|
if (meta.config.enablePostHistory !== 1) {
|
||||||
return callback(null, 0);
|
return callback(null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,14 +10,13 @@ var topics = require('../topics');
|
|||||||
var user = require('../user');
|
var user = require('../user');
|
||||||
var privileges = require('../privileges');
|
var privileges = require('../privileges');
|
||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
var cache = require('./cache');
|
|
||||||
var pubsub = require('../pubsub');
|
var pubsub = require('../pubsub');
|
||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
var translator = require('../translator');
|
var translator = require('../translator');
|
||||||
|
|
||||||
module.exports = function (Posts) {
|
module.exports = function (Posts) {
|
||||||
pubsub.on('post:edit', function (pid) {
|
pubsub.on('post:edit', function (pid) {
|
||||||
cache.del(pid);
|
require('./cache').del(pid);
|
||||||
});
|
});
|
||||||
|
|
||||||
Posts.edit = function (data, callback) {
|
Posts.edit = function (data, callback) {
|
||||||
@@ -67,7 +66,7 @@ module.exports = function (Posts) {
|
|||||||
Posts.setPostFields(data.pid, postData, next);
|
Posts.setPostFields(data.pid, postData, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
if (parseInt(meta.config.enablePostHistory || 1, 10) !== 1) {
|
if (meta.config.enablePostHistory !== 1) {
|
||||||
return setImmediate(next);
|
return setImmediate(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +78,7 @@ module.exports = function (Posts) {
|
|||||||
postData.topic = results.topic;
|
postData.topic = results.topic;
|
||||||
plugins.fireHook('action:post.edit', { post: _.clone(postData), data: data, uid: data.uid });
|
plugins.fireHook('action:post.edit', { post: _.clone(postData), data: data, uid: data.uid });
|
||||||
|
|
||||||
cache.del(String(postData.pid));
|
require('./cache').del(String(postData.pid));
|
||||||
pubsub.publish('post:edit', String(postData.pid));
|
pubsub.publish('post:edit', String(postData.pid));
|
||||||
|
|
||||||
Posts.parsePost(postData, next);
|
Posts.parsePost(postData, next);
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ var url = require('url');
|
|||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
|
|
||||||
var meta = require('../meta');
|
var meta = require('../meta');
|
||||||
var cache = require('./cache');
|
|
||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
var translator = require('../translator');
|
var translator = require('../translator');
|
||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
@@ -24,7 +23,7 @@ module.exports = function (Posts) {
|
|||||||
|
|
||||||
Posts.parsePost = function (postData, callback) {
|
Posts.parsePost = function (postData, callback) {
|
||||||
postData.content = String(postData.content || '');
|
postData.content = String(postData.content || '');
|
||||||
|
var cache = require('./cache');
|
||||||
if (postData.pid && cache.has(String(postData.pid))) {
|
if (postData.pid && cache.has(String(postData.pid))) {
|
||||||
postData.content = cache.get(String(postData.pid));
|
postData.content = cache.get(String(postData.pid));
|
||||||
cache.hits += 1;
|
cache.hits += 1;
|
||||||
@@ -86,11 +85,11 @@ module.exports = function (Posts) {
|
|||||||
signature = translator.escape(signature);
|
signature = translator.escape(signature);
|
||||||
var tagsToStrip = [];
|
var tagsToStrip = [];
|
||||||
|
|
||||||
if (parseInt(meta.config['signatures:disableLinks'], 10) === 1) {
|
if (meta.config['signatures:disableLinks']) {
|
||||||
tagsToStrip.push('a');
|
tagsToStrip.push('a');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(meta.config['signatures:disableImages'], 10) === 1) {
|
if (meta.config['signatures:disableImages']) {
|
||||||
tagsToStrip.push('img');
|
tagsToStrip.push('img');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ module.exports = function (Posts) {
|
|||||||
Posts.shouldQueue = function (uid, data, callback) {
|
Posts.shouldQueue = function (uid, data, callback) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
user.getUserFields(uid, ['reputation', 'postcount'], next);
|
user.getUserFields(uid, ['uid', 'reputation', 'postcount'], next);
|
||||||
},
|
},
|
||||||
function (userData, next) {
|
function (userData, next) {
|
||||||
var shouldQueue = parseInt(meta.config.postQueue, 10) === 1 && (!parseInt(uid, 10) || (parseInt(userData.reputation, 10) <= 0 && parseInt(userData.postcount, 10) <= 0));
|
var shouldQueue = meta.config.postQueue && (!userData.uid || (userData.reputation <= 0 && userData.postcount <= 0));
|
||||||
plugins.fireHook('filter:post.shouldQueue', {
|
plugins.fireHook('filter:post.shouldQueue', {
|
||||||
shouldQueue: shouldQueue,
|
shouldQueue: shouldQueue,
|
||||||
uid: uid,
|
uid: uid,
|
||||||
@@ -199,8 +199,8 @@ module.exports = function (Posts) {
|
|||||||
function (postData, next) {
|
function (postData, next) {
|
||||||
var result = {
|
var result = {
|
||||||
posts: [postData],
|
posts: [postData],
|
||||||
'reputation:disabled': parseInt(meta.config['reputation:disabled'], 10) === 1,
|
'reputation:disabled': !!meta.config['reputation:disabled'],
|
||||||
'downvote:disabled': parseInt(meta.config['downvote:disabled'], 10) === 1,
|
'downvote:disabled': !!meta.config['downvote:disabled'],
|
||||||
};
|
};
|
||||||
socketHelpers.notifyNew(data.uid, 'newPost', result);
|
socketHelpers.notifyNew(data.uid, 'newPost', result);
|
||||||
next();
|
next();
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
|
||||||
var privileges = require('../privileges');
|
var privileges = require('../privileges');
|
||||||
var cache = require('./cache');
|
|
||||||
|
|
||||||
module.exports = function (Posts) {
|
module.exports = function (Posts) {
|
||||||
Posts.tools = {};
|
Posts.tools = {};
|
||||||
@@ -42,7 +41,7 @@ module.exports = function (Posts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isDelete) {
|
if (isDelete) {
|
||||||
cache.del(pid);
|
require('./cache').del(pid);
|
||||||
Posts.delete(pid, uid, next);
|
Posts.delete(pid, uid, next);
|
||||||
} else {
|
} else {
|
||||||
Posts.restore(pid, uid, function (err, postData) {
|
Posts.restore(pid, uid, function (err, postData) {
|
||||||
@@ -65,7 +64,7 @@ module.exports = function (Posts) {
|
|||||||
if (!canPurge) {
|
if (!canPurge) {
|
||||||
return next(new Error('[[error:no-privileges]]'));
|
return next(new Error('[[error:no-privileges]]'));
|
||||||
}
|
}
|
||||||
cache.del(pid);
|
require('./cache').del(pid);
|
||||||
Posts.purge(pid, uid, next);
|
Posts.purge(pid, uid, next);
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ module.exports = function (Posts) {
|
|||||||
userData.fullname = userSettings[index].showfullname ? validator.escape(String(userData.fullname || '')) : undefined;
|
userData.fullname = userSettings[index].showfullname ? validator.escape(String(userData.fullname || '')) : undefined;
|
||||||
userData.selectedGroups = [];
|
userData.selectedGroups = [];
|
||||||
|
|
||||||
if (parseInt(meta.config.hideFullname, 10) === 1) {
|
if (meta.config.hideFullname) {
|
||||||
userData.fullname = undefined;
|
userData.fullname = undefined;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -88,7 +88,7 @@ module.exports = function (Posts) {
|
|||||||
groups.isMemberOfGroups(userData.uid, userData.groupTitleArray, next);
|
groups.isMemberOfGroups(userData.uid, userData.groupTitleArray, next);
|
||||||
},
|
},
|
||||||
signature: function (next) {
|
signature: function (next) {
|
||||||
if (!userData.signature || !canUseSignature || parseInt(meta.config.disableSignatures, 10) === 1) {
|
if (!userData.signature || !canUseSignature || meta.config.disableSignatures) {
|
||||||
userData.signature = '';
|
userData.signature = '';
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ module.exports = function (Posts) {
|
|||||||
var votesInProgress = {};
|
var votesInProgress = {};
|
||||||
|
|
||||||
Posts.upvote = function (pid, uid, callback) {
|
Posts.upvote = function (pid, uid, callback) {
|
||||||
if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
|
if (meta.config['reputation:disabled']) {
|
||||||
return callback(new Error('[[error:reputation-system-disabled]]'));
|
return callback(new Error('[[error:reputation-system-disabled]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,11 +40,11 @@ module.exports = function (Posts) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Posts.downvote = function (pid, uid, callback) {
|
Posts.downvote = function (pid, uid, callback) {
|
||||||
if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
|
if (meta.config['reputation:disabled']) {
|
||||||
return callback(new Error('[[error:reputation-system-disabled]]'));
|
return callback(new Error('[[error:reputation-system-disabled]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(meta.config['downvote:disabled'], 10) === 1) {
|
if (meta.config['downvote:disabled']) {
|
||||||
return callback(new Error('[[error:downvoting-disabled]]'));
|
return callback(new Error('[[error:downvoting-disabled]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +179,7 @@ module.exports = function (Posts) {
|
|||||||
return callback(new Error('[[error:self-vote]]'));
|
return callback(new Error('[[error:self-vote]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command === 'downvote' && parseInt(results.reputation, 10) < parseInt(meta.config['min:rep:downvote'], 10)) {
|
if (command === 'downvote' && results.reputation < meta.config['min:rep:downvote']) {
|
||||||
return callback(new Error('[[error:not-enough-reputation-to-downvote]]'));
|
return callback(new Error('[[error:not-enough-reputation-to-downvote]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ var topics = require('../topics');
|
|||||||
var user = require('../user');
|
var user = require('../user');
|
||||||
var helpers = require('./helpers');
|
var helpers = require('./helpers');
|
||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
var utils = require('../utils');
|
|
||||||
|
|
||||||
module.exports = function (privileges) {
|
module.exports = function (privileges) {
|
||||||
privileges.posts = {};
|
privileges.posts = {};
|
||||||
@@ -184,7 +183,7 @@ module.exports = function (privileges) {
|
|||||||
return next(null, { flag: false, message: '[[error:no-privileges]]' });
|
return next(null, { flag: false, message: '[[error:no-privileges]]' });
|
||||||
}
|
}
|
||||||
|
|
||||||
var postDeleteDuration = parseInt(meta.config.postDeleteDuration, 10);
|
var postDeleteDuration = meta.config.postDeleteDuration;
|
||||||
if (postDeleteDuration && (Date.now() - parseInt(postData.timestamp, 10) > postDeleteDuration * 1000)) {
|
if (postDeleteDuration && (Date.now() - parseInt(postData.timestamp, 10) > postDeleteDuration * 1000)) {
|
||||||
return next(null, { flag: false, message: '[[error:post-delete-duration-expired, ' + meta.config.postDeleteDuration + ']]' });
|
return next(null, { flag: false, message: '[[error:post-delete-duration-expired, ' + meta.config.postDeleteDuration + ']]' });
|
||||||
}
|
}
|
||||||
@@ -204,8 +203,8 @@ module.exports = function (privileges) {
|
|||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
var minimumReputation = utils.isNumber(meta.config['min:rep:flag']) ? parseInt(meta.config['min:rep:flag'], 10) : 0;
|
var minimumReputation = meta.config['min:rep:flag'];
|
||||||
var canFlag = results.isAdminOrMod || parseInt(results.userReputation, 10) >= minimumReputation;
|
var canFlag = results.isAdminOrMod || (results.userReputation >= minimumReputation);
|
||||||
next(null, { flag: canFlag });
|
next(null, { flag: canFlag });
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
@@ -249,8 +248,8 @@ module.exports = function (privileges) {
|
|||||||
posts.getPostFields(pid, ['tid', 'timestamp'], next);
|
posts.getPostFields(pid, ['tid', 'timestamp'], next);
|
||||||
},
|
},
|
||||||
function (postData, next) {
|
function (postData, next) {
|
||||||
var postEditDuration = parseInt(meta.config.postEditDuration, 10);
|
var postEditDuration = meta.config.postEditDuration;
|
||||||
if (postEditDuration && Date.now() - parseInt(postData.timestamp, 10) > postEditDuration * 1000) {
|
if (postEditDuration && (Date.now() - postData.timestamp > postEditDuration * 1000)) {
|
||||||
return callback(null, { flag: false, message: '[[error:post-edit-duration-expired, ' + meta.config.postEditDuration + ']]' });
|
return callback(null, { flag: false, message: '[[error:post-edit-duration-expired, ' + meta.config.postEditDuration + ']]' });
|
||||||
}
|
}
|
||||||
topics.isLocked(postData.tid, next);
|
topics.isLocked(postData.tid, next);
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ module.exports = function (privileges) {
|
|||||||
return next(null, true);
|
return next(null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
var preventTopicDeleteAfterReplies = parseInt(meta.config.preventTopicDeleteAfterReplies, 10) || 0;
|
var preventTopicDeleteAfterReplies = meta.config.preventTopicDeleteAfterReplies;
|
||||||
if (preventTopicDeleteAfterReplies && (topicData.postcount - 1) >= preventTopicDeleteAfterReplies) {
|
if (preventTopicDeleteAfterReplies && (topicData.postcount - 1) >= preventTopicDeleteAfterReplies) {
|
||||||
var langKey = preventTopicDeleteAfterReplies > 1 ?
|
var langKey = preventTopicDeleteAfterReplies > 1 ?
|
||||||
'[[error:cant-delete-topic-has-replies, ' + meta.config.preventTopicDeleteAfterReplies + ']]' :
|
'[[error:cant-delete-topic-has-replies, ' + meta.config.preventTopicDeleteAfterReplies + ']]' :
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ function validateTokenIfRequiresLogin(requiresLogin, cid, req, res, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForTopic(req, res, callback) {
|
function generateForTopic(req, res, callback) {
|
||||||
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
if (meta.config['feeds:disableRSS']) {
|
||||||
return controllers404.send404(req, res);
|
return controllers404.send404(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ function generateForTopic(req, res, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForCategory(req, res, next) {
|
function generateForCategory(req, res, next) {
|
||||||
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
if (meta.config['feeds:disableRSS']) {
|
||||||
return controllers404.send404(req, res);
|
return controllers404.send404(req, res);
|
||||||
}
|
}
|
||||||
var cid = req.params.category_id;
|
var cid = req.params.category_id;
|
||||||
@@ -195,7 +195,7 @@ function generateForCategory(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForTopics(req, res, next) {
|
function generateForTopics(req, res, next) {
|
||||||
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
if (meta.config['feeds:disableRSS']) {
|
||||||
return controllers404.send404(req, res);
|
return controllers404.send404(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +220,7 @@ function generateForTopics(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForRecent(req, res, next) {
|
function generateForRecent(req, res, next) {
|
||||||
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
if (meta.config['feeds:disableRSS']) {
|
||||||
return controllers404.send404(req, res);
|
return controllers404.send404(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +245,7 @@ function generateForRecent(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForTop(req, res, next) {
|
function generateForTop(req, res, next) {
|
||||||
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
if (meta.config['feeds:disableRSS']) {
|
||||||
return controllers404.send404(req, res);
|
return controllers404.send404(req, res);
|
||||||
}
|
}
|
||||||
var term = terms[req.params.term] || 'day';
|
var term = terms[req.params.term] || 'day';
|
||||||
@@ -285,7 +285,7 @@ function generateForTop(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForPopular(req, res, next) {
|
function generateForPopular(req, res, next) {
|
||||||
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
if (meta.config['feeds:disableRSS']) {
|
||||||
return controllers404.send404(req, res);
|
return controllers404.send404(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,7 +387,7 @@ function generateTopicsFeed(feedOptions, feedTopics, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForRecentPosts(req, res, next) {
|
function generateForRecentPosts(req, res, next) {
|
||||||
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
if (meta.config['feeds:disableRSS']) {
|
||||||
return controllers404.send404(req, res);
|
return controllers404.send404(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,7 +409,7 @@ function generateForRecentPosts(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForCategoryRecentPosts(req, res, callback) {
|
function generateForCategoryRecentPosts(req, res, callback) {
|
||||||
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
if (meta.config['feeds:disableRSS']) {
|
||||||
return controllers404.send404(req, res);
|
return controllers404.send404(req, res);
|
||||||
}
|
}
|
||||||
var cid = req.params.category_id;
|
var cid = req.params.category_id;
|
||||||
@@ -475,7 +475,7 @@ function generateForPostsFeed(feedOptions, posts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForUserTopics(req, res, callback) {
|
function generateForUserTopics(req, res, callback) {
|
||||||
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
if (meta.config['feeds:disableRSS']) {
|
||||||
return controllers404.send404(req, res);
|
return controllers404.send404(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -504,7 +504,7 @@ function generateForUserTopics(req, res, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateForTag(req, res, next) {
|
function generateForTag(req, res, next) {
|
||||||
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
if (meta.config['feeds:disableRSS']) {
|
||||||
return controllers404.send404(req, res);
|
return controllers404.send404(req, res);
|
||||||
}
|
}
|
||||||
var tag = validator.escape(String(req.params.tag));
|
var tag = validator.escape(String(req.params.tag));
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ var sitemap = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
sitemap.render = function (callback) {
|
sitemap.render = function (callback) {
|
||||||
var topicsPerPage = parseInt(meta.config.sitemapTopics, 10) || 500;
|
var topicsPerPage = meta.config.sitemapTopics;
|
||||||
var returnData = {
|
var returnData = {
|
||||||
url: nconf.get('url'),
|
url: nconf.get('url'),
|
||||||
topics: [],
|
topics: [],
|
||||||
@@ -119,7 +119,7 @@ sitemap.getTopicPage = function (page, callback) {
|
|||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
var numTopics = parseInt(meta.config.sitemapTopics, 10) || 500;
|
var numTopics = meta.config.sitemapTopics;
|
||||||
var min = (parseInt(page, 10) - 1) * numTopics;
|
var min = (parseInt(page, 10) - 1) * numTopics;
|
||||||
var max = min + numTopics;
|
var max = min + numTopics;
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ User.sendValidationEmail = function (socket, uids, callback) {
|
|||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(meta.config.requireEmailConfirmation, 10) !== 1) {
|
if (!meta.config.requireEmailConfirmation) {
|
||||||
return callback(new Error('[[error:email-confirmations-are-disabled]]'));
|
return callback(new Error('[[error:email-confirmations-are-disabled]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ SocketGroups.join = function (socket, data, callback) {
|
|||||||
return next(new Error('[[error:no-group]]'));
|
return next(new Error('[[error:no-group]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(meta.config.allowPrivateGroups, 10) !== 1) {
|
if (!meta.config.allowPrivateGroups) {
|
||||||
return groups.join(data.groupName, socket.uid, callback);
|
return groups.join(data.groupName, socket.uid, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +238,7 @@ SocketGroups.kick = isOwner(function (socket, data, callback) {
|
|||||||
SocketGroups.create = function (socket, data, callback) {
|
SocketGroups.create = function (socket, data, callback) {
|
||||||
if (!socket.uid) {
|
if (!socket.uid) {
|
||||||
return callback(new Error('[[error:no-privileges]]'));
|
return callback(new Error('[[error:no-privileges]]'));
|
||||||
} else if (parseInt(meta.config.allowGroupCreation, 10) !== 1) {
|
} else if (!meta.config.allowGroupCreation) {
|
||||||
return callback(new Error('[[error:group-creation-disabled]]'));
|
return callback(new Error('[[error:group-creation-disabled]]'));
|
||||||
} else if (groups.isPrivilegeGroup(data.name)) {
|
} else if (groups.isPrivilegeGroup(data.name)) {
|
||||||
return callback(new Error('[[error:invalid-group-name]]'));
|
return callback(new Error('[[error:invalid-group-name]]'));
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ function requireModules() {
|
|||||||
|
|
||||||
function checkMaintenance(socket, callback) {
|
function checkMaintenance(socket, callback) {
|
||||||
var meta = require('../meta');
|
var meta = require('../meta');
|
||||||
if (parseInt(meta.config.maintenanceMode, 10) !== 1) {
|
if (!meta.config.maintenanceMode) {
|
||||||
return setImmediate(callback);
|
return setImmediate(callback);
|
||||||
}
|
}
|
||||||
user.isAdministrator(socket.uid, function (err, isAdmin) {
|
user.isAdministrator(socket.uid, function (err, isAdmin) {
|
||||||
|
|||||||
@@ -137,8 +137,7 @@ SocketModules.chats.send = function (socket, data, callback) {
|
|||||||
function rateLimitExceeded(socket) {
|
function rateLimitExceeded(socket) {
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
socket.lastChatMessageTime = socket.lastChatMessageTime || 0;
|
socket.lastChatMessageTime = socket.lastChatMessageTime || 0;
|
||||||
var delay = meta.config.hasOwnProperty('chatMessageDelay') ? parseInt(meta.config.chatMessageDelay, 10) : 200;
|
if (now - socket.lastChatMessageTime < meta.config.chatMessageDelay) {
|
||||||
if (now - socket.lastChatMessageTime < delay) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
socket.lastChatMessageTime = now;
|
socket.lastChatMessageTime = now;
|
||||||
@@ -193,7 +192,7 @@ SocketModules.chats.addUserToRoom = function (socket, data, callback) {
|
|||||||
Messaging.getUserCountInRoom(data.roomId, next);
|
Messaging.getUserCountInRoom(data.roomId, next);
|
||||||
},
|
},
|
||||||
function (userCount, next) {
|
function (userCount, next) {
|
||||||
var maxUsers = parseInt(meta.config.maximumUsersInChatRoom, 10) || 0;
|
var maxUsers = meta.config.maximumUsersInChatRoom;
|
||||||
if (maxUsers && userCount >= maxUsers) {
|
if (maxUsers && userCount >= maxUsers) {
|
||||||
return next(new Error('[[error:cant-add-more-users-to-chat-room]]'));
|
return next(new Error('[[error:cant-add-more-users-to-chat-room]]'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ require('./posts/tools')(SocketPosts);
|
|||||||
require('./posts/diffs')(SocketPosts);
|
require('./posts/diffs')(SocketPosts);
|
||||||
|
|
||||||
SocketPosts.reply = function (socket, data, callback) {
|
SocketPosts.reply = function (socket, data, callback) {
|
||||||
if (!data || !data.tid || (parseInt(meta.config.minimumPostLength, 10) !== 0 && !data.content)) {
|
if (!data || !data.tid || (meta.config.minimumPostLength !== 0 && !data.content)) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,8 +57,8 @@ function postReply(socket, data, callback) {
|
|||||||
function (postData, next) {
|
function (postData, next) {
|
||||||
var result = {
|
var result = {
|
||||||
posts: [postData],
|
posts: [postData],
|
||||||
'reputation:disabled': parseInt(meta.config['reputation:disabled'], 10) === 1,
|
'reputation:disabled': meta.config['reputation:disabled'] === 1,
|
||||||
'downvote:disabled': parseInt(meta.config['downvote:disabled'], 10) === 1,
|
'downvote:disabled': meta.config['downvote:disabled'] === 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
next(null, postData);
|
next(null, postData);
|
||||||
|
|||||||
@@ -15,24 +15,24 @@ module.exports = function (SocketPosts) {
|
|||||||
SocketPosts.edit = function (socket, data, callback) {
|
SocketPosts.edit = function (socket, data, callback) {
|
||||||
if (!socket.uid) {
|
if (!socket.uid) {
|
||||||
return callback(new Error('[[error:not-logged-in]]'));
|
return callback(new Error('[[error:not-logged-in]]'));
|
||||||
} else if (!data || !data.pid || (parseInt(meta.config.minimumPostLength, 10) !== 0 && !data.content)) {
|
} else if (!data || !data.pid || (meta.config.minimumPostLength !== 0 && !data.content)) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim and remove HTML (latter for composers that send in HTML, like redactor)
|
// Trim and remove HTML (latter for composers that send in HTML, like redactor)
|
||||||
var contentLen = utils.stripHTMLTags(data.content).trim().length;
|
var contentLen = utils.stripHTMLTags(data.content).trim().length;
|
||||||
|
|
||||||
if (data.title && data.title.length < parseInt(meta.config.minimumTitleLength, 10)) {
|
if (data.title && data.title.length < meta.config.minimumTitleLength) {
|
||||||
return callback(new Error('[[error:title-too-short, ' + meta.config.minimumTitleLength + ']]'));
|
return callback(new Error('[[error:title-too-short, ' + meta.config.minimumTitleLength + ']]'));
|
||||||
} else if (data.title && data.title.length > parseInt(meta.config.maximumTitleLength, 10)) {
|
} else if (data.title && data.title.length > meta.config.maximumTitleLength) {
|
||||||
return callback(new Error('[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]'));
|
return callback(new Error('[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]'));
|
||||||
} else if (data.tags && data.tags.length < parseInt(meta.config.minimumTagsPerTopic, 10)) {
|
} else if (data.tags && data.tags.length < meta.config.minimumTagsPerTopic) {
|
||||||
return callback(new Error('[[error:not-enough-tags, ' + meta.config.minimumTagsPerTopic + ']]'));
|
return callback(new Error('[[error:not-enough-tags, ' + meta.config.minimumTagsPerTopic + ']]'));
|
||||||
} else if (data.tags && data.tags.length > parseInt(meta.config.maximumTagsPerTopic, 10)) {
|
} else if (data.tags && data.tags.length > meta.config.maximumTagsPerTopic) {
|
||||||
return callback(new Error('[[error:too-many-tags, ' + meta.config.maximumTagsPerTopic + ']]'));
|
return callback(new Error('[[error:too-many-tags, ' + meta.config.maximumTagsPerTopic + ']]'));
|
||||||
} else if (parseInt(meta.config.minimumPostLength, 10) !== 0 && contentLen < parseInt(meta.config.minimumPostLength, 10)) {
|
} else if (meta.config.minimumPostLength !== 0 && contentLen < meta.config.minimumPostLength) {
|
||||||
return callback(new Error('[[error:content-too-short, ' + meta.config.minimumPostLength + ']]'));
|
return callback(new Error('[[error:content-too-short, ' + meta.config.minimumPostLength + ']]'));
|
||||||
} else if (contentLen > parseInt(meta.config.maximumPostLength, 10)) {
|
} else if (contentLen > meta.config.maximumPostLength) {
|
||||||
return callback(new Error('[[error:content-too-long, ' + meta.config.maximumPostLength + ']]'));
|
return callback(new Error('[[error:content-too-long, ' + meta.config.maximumPostLength + ']]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ module.exports = function (SocketPosts) {
|
|||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
if (parseInt(meta.config.votesArePublic, 10) !== 0) {
|
if (meta.config.votesArePublic) {
|
||||||
return next(null, true);
|
return next(null, true);
|
||||||
}
|
}
|
||||||
privileges.categories.isAdminOrMod(data.cid, socket.uid, next);
|
privileges.categories.isAdminOrMod(data.cid, socket.uid, next);
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ module.exports = function (SocketTopics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
topicData.privileges = userPrivileges;
|
topicData.privileges = userPrivileges;
|
||||||
topicData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
|
topicData['reputation:disabled'] = meta.config['reputation:disabled'] === 1;
|
||||||
topicData['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1;
|
topicData['downvote:disabled'] = meta.config['downvote:disabled'] === 1;
|
||||||
|
|
||||||
topics.modifyPostsByPrivilege(topicData, userPrivileges);
|
topics.modifyPostsByPrivilege(topicData, userPrivileges);
|
||||||
next(null, topicData);
|
next(null, topicData);
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ SocketUser.emailConfirm = function (socket, data, callback) {
|
|||||||
return callback(new Error('[[error:no-privileges]]'));
|
return callback(new Error('[[error:no-privileges]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(meta.config.requireEmailConfirmation, 10) !== 1) {
|
if (!meta.config.requireEmailConfirmation) {
|
||||||
return callback(new Error('[[error:email-confirmations-are-disabled]]'));
|
return callback(new Error('[[error:email-confirmations-are-disabled]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,7 +297,7 @@ SocketUser.invite = function (socket, email, callback) {
|
|||||||
if (registrationType === 'admin-invite-only' && !isAdmin) {
|
if (registrationType === 'admin-invite-only' && !isAdmin) {
|
||||||
return next(new Error('[[error:no-privileges]]'));
|
return next(new Error('[[error:no-privileges]]'));
|
||||||
}
|
}
|
||||||
var max = parseInt(meta.config.maximumInvites, 10);
|
var max = meta.config.maximumInvites;
|
||||||
email = email.split(',').map(email => email.trim()).filter(Boolean);
|
email = email.split(',').map(email => email.trim()).filter(Boolean);
|
||||||
async.eachSeries(email, function (email, next) {
|
async.eachSeries(email, function (email, next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
|||||||
@@ -171,11 +171,11 @@ module.exports = function (SocketUser) {
|
|||||||
return next(new Error('[[error:no-privileges]]'));
|
return next(new Error('[[error:no-privileges]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!results.isAdminOrGlobalMod && parseInt(meta.config['username:disableEdit'], 10) === 1) {
|
if (!results.isAdminOrGlobalMod && meta.config['username:disableEdit']) {
|
||||||
data.username = oldUserData.username;
|
data.username = oldUserData.username;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!results.isAdminOrGlobalMod && parseInt(meta.config['email:disableEdit'], 10) === 1) {
|
if (!results.isAdminOrGlobalMod && meta.config['email:disableEdit']) {
|
||||||
data.email = oldUserData.email;
|
data.email = oldUserData.email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ Topics.getTopicsByTids = function (tids, uid, callback) {
|
|||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
results.users.forEach(function (user, index) {
|
results.users.forEach(function (user, index) {
|
||||||
if (parseInt(meta.config.hideFullname, 10) === 1 || !results.userSettings[index].showfullname) {
|
if (meta.config.hideFullname || !results.userSettings[index].showfullname) {
|
||||||
user.fullname = undefined;
|
user.fullname = undefined;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ module.exports = function (Topics) {
|
|||||||
postData.index = parseInt(results.topicInfo.postcount, 10) - 1;
|
postData.index = parseInt(results.topicInfo.postcount, 10) - 1;
|
||||||
|
|
||||||
// Username override for guests, if enabled
|
// Username override for guests, if enabled
|
||||||
if (parseInt(meta.config.allowGuestHandles, 10) === 1 && parseInt(postData.uid, 10) === 0 && data.handle) {
|
if (meta.config.allowGuestHandles && postData.uid === 0 && data.handle) {
|
||||||
postData.user.username = validator.escape(String(data.handle));
|
postData.user.username = validator.escape(String(data.handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,7 +348,7 @@ module.exports = function (Topics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function guestHandleValid(data, callback) {
|
function guestHandleValid(data, callback) {
|
||||||
if (parseInt(meta.config.allowGuestHandles, 10) === 1 && parseInt(data.uid, 10) === 0 && data.handle) {
|
if (meta.config.allowGuestHandles && parseInt(data.uid, 10) === 0 && data.handle) {
|
||||||
if (data.handle.length > meta.config.maximumUsernameLength) {
|
if (data.handle.length > meta.config.maximumUsernameLength) {
|
||||||
return callback(new Error('[[error:guest-handle-invalid]]'));
|
return callback(new Error('[[error:guest-handle-invalid]]'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ var categories = require('../categories');
|
|||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
var translator = require('../translator');
|
var translator = require('../translator');
|
||||||
|
|
||||||
const intFields = ['tid', 'cid', 'uid', 'mainPid', 'deleted', 'locked', 'pinned'];
|
const intFields = [
|
||||||
|
'tid', 'cid', 'uid', 'mainPid', 'deleted', 'locked', 'pinned',
|
||||||
|
'timestamp',
|
||||||
|
];
|
||||||
|
|
||||||
module.exports = function (Topics) {
|
module.exports = function (Topics) {
|
||||||
Topics.getTopicsFields = function (tids, fields, callback) {
|
Topics.getTopicsFields = function (tids, fields, callback) {
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ module.exports = function (Topics) {
|
|||||||
title = title.trim();
|
title = title.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (title.length < parseInt(meta.config.minimumTitleLength, 10)) {
|
if (title.length < meta.config.minimumTitleLength) {
|
||||||
return callback(new Error('[[error:title-too-short, ' + meta.config.minimumTitleLength + ']]'));
|
return callback(new Error('[[error:title-too-short, ' + meta.config.minimumTitleLength + ']]'));
|
||||||
} else if (title.length > parseInt(meta.config.maximumTitleLength, 10)) {
|
} else if (title.length > meta.config.maximumTitleLength) {
|
||||||
return callback(new Error('[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]'));
|
return callback(new Error('[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ module.exports = function (Topics) {
|
|||||||
postObj.selfPost = !!parseInt(uid, 10) && parseInt(uid, 10) === parseInt(postObj.uid, 10);
|
postObj.selfPost = !!parseInt(uid, 10) && parseInt(uid, 10) === parseInt(postObj.uid, 10);
|
||||||
|
|
||||||
// Username override for guests, if enabled
|
// Username override for guests, if enabled
|
||||||
if (parseInt(meta.config.allowGuestHandles, 10) === 1 && parseInt(postObj.uid, 10) === 0 && postObj.handle) {
|
if (meta.config.allowGuestHandles && postObj.uid === 0 && postObj.handle) {
|
||||||
postObj.user.username = validator.escape(String(postObj.handle));
|
postObj.user.username = validator.escape(String(postObj.handle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ module.exports = function (Topics) {
|
|||||||
function (tids, next) {
|
function (tids, next) {
|
||||||
async.parallel({
|
async.parallel({
|
||||||
ignoredCids: function (next) {
|
ignoredCids: function (next) {
|
||||||
if (filter === 'watched' || parseInt(meta.config.disableRecentCategoryFilter, 10) === 1) {
|
if (filter === 'watched' || meta.config.disableRecentCategoryFilter) {
|
||||||
return next(null, []);
|
return next(null, []);
|
||||||
}
|
}
|
||||||
user.getIgnoredCategories(uid, next);
|
user.getIgnoredCategories(uid, next);
|
||||||
|
|||||||
@@ -485,7 +485,7 @@ module.exports = function (Topics) {
|
|||||||
return plugins.fireHook('filter:topic.getRelatedTopics', { topic: topicData, uid: uid }, callback);
|
return plugins.fireHook('filter:topic.getRelatedTopics', { topic: topicData, uid: uid }, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
var maximumTopics = parseInt(meta.config.maximumRelatedTopics, 10) || 0;
|
var maximumTopics = meta.config.maximumRelatedTopics;
|
||||||
if (maximumTopics === 0 || !topicData.tags || !topicData.tags.length) {
|
if (maximumTopics === 0 || !topicData.tags || !topicData.tags.length) {
|
||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,11 +46,10 @@ module.exports = function (Topics) {
|
|||||||
file.isFileTypeAllowed(pathToUpload, next);
|
file.isFileTypeAllowed(pathToUpload, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
var size = parseInt(meta.config.topicThumbSize, 10) || 120;
|
|
||||||
image.resizeImage({
|
image.resizeImage({
|
||||||
path: pathToUpload,
|
path: pathToUpload,
|
||||||
width: size,
|
width: meta.config.topicThumbSize,
|
||||||
height: size,
|
height: meta.config.topicThumbSize,
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
|
|||||||
@@ -60,8 +60,7 @@ module.exports = function (Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.unreadCutoff = function () {
|
Topics.unreadCutoff = function () {
|
||||||
var cutoff = parseInt(meta.config.unreadCutoff, 10) || 2;
|
return Date.now() - (meta.config.unreadCutoff * 86400000);
|
||||||
return Date.now() - (cutoff * 86400000);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.getUnreadTids = function (params, callback) {
|
Topics.getUnreadTids = function (params, callback) {
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ module.exports = function (User) {
|
|||||||
db.increment('loginAttempts:' + uid, next);
|
db.increment('loginAttempts:' + uid, next);
|
||||||
},
|
},
|
||||||
function (attemps, next) {
|
function (attemps, next) {
|
||||||
var loginAttempts = parseInt(meta.config.loginAttempts, 10) || 5;
|
if (attemps <= meta.config.loginAttempts) {
|
||||||
if (attemps <= loginAttempts) {
|
|
||||||
return db.pexpire('loginAttempts:' + uid, 1000 * 60 * 60, callback);
|
return db.pexpire('loginAttempts:' + uid, 1000 * 60 * 60, callback);
|
||||||
}
|
}
|
||||||
// Lock out the account
|
// Lock out the account
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ module.exports = function (User) {
|
|||||||
async.apply(db.sortedSetAdd, 'user:' + userData.uid + ':emails', timestamp, userData.email),
|
async.apply(db.sortedSetAdd, 'user:' + userData.uid + ':emails', timestamp, userData.email),
|
||||||
], next);
|
], next);
|
||||||
|
|
||||||
if (parseInt(userData.uid, 10) !== 1 && parseInt(meta.config.requireEmailConfirmation, 10) === 1) {
|
if (userData.uid > 1 && meta.config.requireEmailConfirmation) {
|
||||||
User.email.sendValidationEmail(userData.uid, {
|
User.email.sendValidationEmail(userData.uid, {
|
||||||
email: userData.email,
|
email: userData.email,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,7 +11,11 @@ var meta = require('../meta');
|
|||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
|
|
||||||
const intFields = ['uid', 'postcount', 'topiccount', 'banned'];
|
const intFields = [
|
||||||
|
'uid', 'postcount', 'topiccount', 'reputation', 'profileviews',
|
||||||
|
'banned', 'email:confirmed', 'joindate', 'lastonline', 'lastqueuetime',
|
||||||
|
'lastposttime',
|
||||||
|
];
|
||||||
|
|
||||||
module.exports = function (User) {
|
module.exports = function (User) {
|
||||||
var iconBackgrounds = [
|
var iconBackgrounds = [
|
||||||
@@ -205,7 +209,7 @@ module.exports = function (User) {
|
|||||||
if (!Array.isArray(user.groupTitleArray)) {
|
if (!Array.isArray(user.groupTitleArray)) {
|
||||||
user.groupTitleArray = [user.groupTitleArray];
|
user.groupTitleArray = [user.groupTitleArray];
|
||||||
}
|
}
|
||||||
if (parseInt(meta.config.allowMultipleBadges, 10) !== 1) {
|
if (!meta.config.allowMultipleBadges) {
|
||||||
user.groupTitleArray = [user.groupTitleArray[0]];
|
user.groupTitleArray = [user.groupTitleArray[0]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ var Digest = module.exports;
|
|||||||
Digest.execute = function (payload, callback) {
|
Digest.execute = function (payload, callback) {
|
||||||
callback = callback || function () {};
|
callback = callback || function () {};
|
||||||
|
|
||||||
var digestsDisabled = parseInt(meta.config.disableEmailSubscriptions, 10) === 1;
|
var digestsDisabled = meta.config.disableEmailSubscriptions === 1;
|
||||||
if (digestsDisabled) {
|
if (digestsDisabled) {
|
||||||
winston.info('[user/jobs] Did not send digests (' + payload.interval + ') because subscription system is disabled.');
|
winston.info('[user/jobs] Did not send digests (' + payload.interval + ') because subscription system is disabled.');
|
||||||
return callback();
|
return callback();
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ UserEmail.sendValidationEmail = function (uid, options, callback) {
|
|||||||
var confirm_code = utils.generateUUID();
|
var confirm_code = utils.generateUUID();
|
||||||
var confirm_link = nconf.get('url') + '/confirm/' + confirm_code;
|
var confirm_link = nconf.get('url') + '/confirm/' + confirm_code;
|
||||||
|
|
||||||
var emailInterval = meta.config.hasOwnProperty('emailConfirmInterval') ? parseInt(meta.config.emailConfirmInterval, 10) : 10;
|
var emailInterval = meta.config.emailConfirmInterval;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ module.exports = function (User) {
|
|||||||
var token = utils.generateUUID();
|
var token = utils.generateUUID();
|
||||||
var registerLink = nconf.get('url') + '/register?token=' + token + '&email=' + encodeURIComponent(email);
|
var registerLink = nconf.get('url') + '/register?token=' + token + '&email=' + encodeURIComponent(email);
|
||||||
|
|
||||||
var expireDays = (parseInt(meta.config.inviteExpiration, 10) || 7);
|
var expireDays = meta.config.inviteExpiration;
|
||||||
var expireIn = expireDays * 86400000;
|
var expireIn = expireDays * 86400000;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ module.exports = function (User) {
|
|||||||
winston.verbose('[user/jobs] (Re-)starting user jobs...');
|
winston.verbose('[user/jobs] (Re-)starting user jobs...');
|
||||||
|
|
||||||
var started = 0;
|
var started = 0;
|
||||||
var digestHour = parseInt(meta.config.digestHour, 10);
|
var digestHour = meta.config.digestHour;
|
||||||
|
|
||||||
// Fix digest hour if invalid
|
// Fix digest hour if invalid
|
||||||
if (isNaN(digestHour)) {
|
if (isNaN(digestHour)) {
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ module.exports = function (User) {
|
|||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
var size = data.file ? data.file.size : image.sizeFromBase64(data.imageData);
|
var size = data.file ? data.file.size : image.sizeFromBase64(data.imageData);
|
||||||
meta.config.maximumCoverImageSize = meta.config.maximumCoverImageSize || 2048;
|
if (size > meta.config.maximumCoverImageSize * 1024) {
|
||||||
if (size > parseInt(meta.config.maximumCoverImageSize, 10) * 1024) {
|
|
||||||
return next(new Error('[[error:file-too-big, ' + meta.config.maximumCoverImageSize + ']]'));
|
return next(new Error('[[error:file-too-big, ' + meta.config.maximumCoverImageSize + ']]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +80,7 @@ module.exports = function (User) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
User.uploadCroppedPicture = function (data, callback) {
|
User.uploadCroppedPicture = function (data, callback) {
|
||||||
if (parseInt(meta.config.allowProfileImageUploads, 10) !== 1) {
|
if (!meta.config.allowProfileImageUploads) {
|
||||||
return callback(new Error('[[error:profile-image-uploads-disabled]]'));
|
return callback(new Error('[[error:profile-image-uploads-disabled]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +89,7 @@ module.exports = function (User) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var size = data.file ? data.file.size : image.sizeFromBase64(data.imageData);
|
var size = data.file ? data.file.size : image.sizeFromBase64(data.imageData);
|
||||||
var uploadSize = parseInt(meta.config.maximumProfileImageSize, 10) || 256;
|
var uploadSize = meta.config.maximumProfileImageSize;
|
||||||
if (size > uploadSize * 1024) {
|
if (size > uploadSize * 1024) {
|
||||||
return callback(new Error('[[error:file-too-big, ' + uploadSize + ']]'));
|
return callback(new Error('[[error:file-too-big, ' + uploadSize + ']]'));
|
||||||
}
|
}
|
||||||
@@ -123,11 +122,10 @@ module.exports = function (User) {
|
|||||||
},
|
},
|
||||||
function (path, next) {
|
function (path, next) {
|
||||||
picture.path = path;
|
picture.path = path;
|
||||||
var imageDimension = parseInt(meta.config.profileImageDimension, 10) || 200;
|
|
||||||
image.resizeImage({
|
image.resizeImage({
|
||||||
path: picture.path,
|
path: picture.path,
|
||||||
width: imageDimension,
|
width: meta.config.profileImageDimension,
|
||||||
height: imageDimension,
|
height: meta.config.profileImageDimension,
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -149,7 +147,7 @@ module.exports = function (User) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function convertToPNG(path, extension, callback) {
|
function convertToPNG(path, extension, callback) {
|
||||||
var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10) === 1;
|
var convertToPNG = meta.config['profile:convertProfileImageToPNG'] === 1;
|
||||||
if (!convertToPNG) {
|
if (!convertToPNG) {
|
||||||
return setImmediate(callback, null, path);
|
return setImmediate(callback, null, path);
|
||||||
}
|
}
|
||||||
@@ -176,8 +174,8 @@ module.exports = function (User) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateProfileImageFilename(uid, type, extension) {
|
function generateProfileImageFilename(uid, type, extension) {
|
||||||
var keepAllVersions = parseInt(meta.config['profile:keepAllUserImages'], 10) === 1;
|
var keepAllVersions = meta.config['profile:keepAllUserImages'] === 1;
|
||||||
var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10) === 1;
|
var convertToPNG = meta.config['profile:convertProfileImageToPNG'] === 1;
|
||||||
return uid + '-' + type + (keepAllVersions ? '-' + Date.now() : '') + (convertToPNG ? '.png' : extension);
|
return uid + '-' + type + (keepAllVersions ? '-' + Date.now() : '') + (convertToPNG ? '.png' : extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,20 +44,20 @@ module.exports = function (User) {
|
|||||||
return next(new Error('[[error:user-banned]]'));
|
return next(new Error('[[error:user-banned]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) {
|
if (meta.config.requireEmailConfirmation && !userData['email:confirmed']) {
|
||||||
return next(new Error('[[error:email-not-confirmed]]'));
|
return next(new Error('[[error:email-not-confirmed]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
if (now - parseInt(userData.joindate, 10) < parseInt(meta.config.initialPostDelay, 10) * 1000) {
|
if (now - userData.joindate < meta.config.initialPostDelay * 1000) {
|
||||||
return next(new Error('[[error:user-too-new, ' + meta.config.initialPostDelay + ']]'));
|
return next(new Error('[[error:user-too-new, ' + meta.config.initialPostDelay + ']]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
var lasttime = userData[field] || 0;
|
var lasttime = userData[field] || 0;
|
||||||
|
|
||||||
if (parseInt(meta.config.newbiePostDelay, 10) > 0 && parseInt(meta.config.newbiePostDelayThreshold, 10) > parseInt(userData.reputation, 10) && now - parseInt(lasttime, 10) < parseInt(meta.config.newbiePostDelay, 10) * 1000) {
|
if (meta.config.newbiePostDelay > 0 && meta.config.newbiePostDelayThreshold > userData.reputation && now - lasttime < meta.config.newbiePostDelay * 1000) {
|
||||||
return next(new Error('[[error:too-many-posts-newbie, ' + meta.config.newbiePostDelay + ', ' + meta.config.newbiePostDelayThreshold + ']]'));
|
return next(new Error('[[error:too-many-posts-newbie, ' + meta.config.newbiePostDelay + ', ' + meta.config.newbiePostDelayThreshold + ']]'));
|
||||||
} else if (now - parseInt(lasttime, 10) < parseInt(meta.config.postDelay, 10) * 1000) {
|
} else if (now - lasttime < meta.config.postDelay * 1000) {
|
||||||
return next(new Error('[[error:too-many-posts, ' + meta.config.postDelay + ']]'));
|
return next(new Error('[[error:too-many-posts, ' + meta.config.postDelay + ']]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ module.exports = function (User) {
|
|||||||
|
|
||||||
User.checkMinReputation = function (callerUid, uid, setting, callback) {
|
User.checkMinReputation = function (callerUid, uid, setting, callback) {
|
||||||
var isSelf = parseInt(callerUid, 10) === parseInt(uid, 10);
|
var isSelf = parseInt(callerUid, 10) === parseInt(uid, 10);
|
||||||
if (!isSelf || parseInt(meta.config['reputation:disabled'], 10) === 1) {
|
if (!isSelf || meta.config['reputation:disabled']) {
|
||||||
return setImmediate(callback);
|
return setImmediate(callback);
|
||||||
}
|
}
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -176,7 +176,7 @@ module.exports = function (User) {
|
|||||||
User.getUserField(uid, 'reputation', next);
|
User.getUserField(uid, 'reputation', next);
|
||||||
},
|
},
|
||||||
function (reputation, next) {
|
function (reputation, next) {
|
||||||
if (parseInt(reputation, 10) < (parseInt(meta.config[setting], 10) || 0)) {
|
if (reputation < meta.config[setting]) {
|
||||||
return next(new Error('[[error:not-enough-reputation-' + setting.replace(/:/g, '-') + ']]'));
|
return next(new Error('[[error:not-enough-reputation-' + setting.replace(/:/g, '-') + ']]'));
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
@@ -218,7 +218,7 @@ module.exports = function (User) {
|
|||||||
User.setUserField(uid, 'email', newEmail, next);
|
User.setUserField(uid, 'email', newEmail, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && newEmail) {
|
if (meta.config.requireEmailConfirmation && newEmail) {
|
||||||
User.email.sendValidationEmail(uid, {
|
User.email.sendValidationEmail(uid, {
|
||||||
email: newEmail,
|
email: newEmail,
|
||||||
subject: '[[email:email.verify-your-email.subject]]',
|
subject: '[[email:email.verify-your-email.subject]]',
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ UserReset.commit = function (code, password, callback) {
|
|||||||
|
|
||||||
UserReset.updateExpiry = function (uid, callback) {
|
UserReset.updateExpiry = function (uid, callback) {
|
||||||
var oneDay = 1000 * 60 * 60 * 24;
|
var oneDay = 1000 * 60 * 60 * 24;
|
||||||
var expireDays = parseInt(meta.config.passwordExpiryDays || 0, 10);
|
var expireDays = meta.config.passwordExpiryDays;
|
||||||
var expiry = Date.now() + (oneDay * expireDays);
|
var expiry = Date.now() + (oneDay * expireDays);
|
||||||
|
|
||||||
callback = callback || function () {};
|
callback = callback || function () {};
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ module.exports = function (User) {
|
|||||||
searchResult.matchCount = uids.length;
|
searchResult.matchCount = uids.length;
|
||||||
|
|
||||||
if (paginate) {
|
if (paginate) {
|
||||||
var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20;
|
var resultsPerPage = meta.config.userSearchResultsPerPage;
|
||||||
var start = Math.max(0, page - 1) * resultsPerPage;
|
var start = Math.max(0, page - 1) * resultsPerPage;
|
||||||
var stop = start + resultsPerPage;
|
var stop = start + resultsPerPage;
|
||||||
searchResult.pageCount = Math.ceil(uids.length / resultsPerPage);
|
searchResult.pageCount = Math.ceil(uids.length / resultsPerPage);
|
||||||
@@ -64,7 +64,7 @@ module.exports = function (User) {
|
|||||||
var min = query;
|
var min = query;
|
||||||
var max = query.substr(0, query.length - 1) + String.fromCharCode(query.charCodeAt(query.length - 1) + 1);
|
var max = query.substr(0, query.length - 1) + String.fromCharCode(query.charCodeAt(query.length - 1) + 1);
|
||||||
|
|
||||||
var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20;
|
var resultsPerPage = meta.config.userSearchResultsPerPage;
|
||||||
hardCap = hardCap || resultsPerPage * 10;
|
hardCap = hardCap || resultsPerPage * 10;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
|||||||
@@ -31,9 +31,7 @@ module.exports = function (User) {
|
|||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
var keys = uids.map(function (uid) {
|
var keys = uids.map(uid => 'user:' + uid + ':settings');
|
||||||
return 'user:' + uid + ':settings';
|
|
||||||
});
|
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -60,8 +58,8 @@ module.exports = function (User) {
|
|||||||
function (data, next) {
|
function (data, next) {
|
||||||
settings = data.settings;
|
settings = data.settings;
|
||||||
|
|
||||||
var defaultTopicsPerPage = parseInt(meta.config.topicsPerPage, 10) || 20;
|
var defaultTopicsPerPage = meta.config.topicsPerPage;
|
||||||
var defaultPostsPerPage = parseInt(meta.config.postsPerPage, 10) || 20;
|
var defaultPostsPerPage = meta.config.postsPerPage;
|
||||||
|
|
||||||
settings.showemail = parseInt(getSetting(settings, 'showemail', 0), 10) === 1;
|
settings.showemail = parseInt(getSetting(settings, 'showemail', 0), 10) === 1;
|
||||||
settings.showfullname = parseInt(getSetting(settings, 'showfullname', 0), 10) === 1;
|
settings.showfullname = parseInt(getSetting(settings, 'showfullname', 0), 10) === 1;
|
||||||
|
|||||||
@@ -179,12 +179,11 @@ function setupExpressApp(app, callback) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
var hsts_option = {
|
var hsts_option = {
|
||||||
maxAge: parseInt(meta.config['hsts-maxage'], 10) || 31536000,
|
maxAge: meta.config['hsts-maxage'],
|
||||||
includeSubdomains: !!parseInt(meta.config['hsts-subdomains'], 10),
|
includeSubdomains: !!meta.config['hsts-subdomains'],
|
||||||
preload: !!parseInt(meta.config['hsts-preload'], 10),
|
preload: !!meta.config['hsts-preload'],
|
||||||
setIf: function () {
|
setIf: function () {
|
||||||
// If not set, default to on - previous and recommended behavior
|
return !!meta.config['hsts-enabled'];
|
||||||
return meta.config['hsts-enabled'] === undefined || !!parseInt(meta.config['hsts-enabled'], 10);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
app.use(helmet({
|
app.use(helmet({
|
||||||
@@ -196,8 +195,8 @@ function setupExpressApp(app, callback) {
|
|||||||
auth.initialize(app, middleware);
|
auth.initialize(app, middleware);
|
||||||
|
|
||||||
var toobusy = require('toobusy-js');
|
var toobusy = require('toobusy-js');
|
||||||
toobusy.maxLag(parseInt(meta.config.eventLoopLagThreshold, 10) || 100);
|
toobusy.maxLag(meta.config.eventLoopLagThreshold);
|
||||||
toobusy.interval(parseInt(meta.config.eventLoopInterval, 10) || 500);
|
toobusy.interval(meta.config.eventLoopInterval);
|
||||||
|
|
||||||
setupAutoLocale(app, callback);
|
setupAutoLocale(app, callback);
|
||||||
}
|
}
|
||||||
@@ -246,7 +245,7 @@ function setupAutoLocale(app, callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
if (parseInt(req.uid, 10) > 0 || parseInt(meta.config.autoDetectLang, 10) !== 1) {
|
if (parseInt(req.uid, 10) > 0 || !meta.config.autoDetectLang) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
54
test/meta.js
54
test/meta.js
@@ -105,8 +105,8 @@ describe('meta', function () {
|
|||||||
it('should get config fields', function (done) {
|
it('should get config fields', function (done) {
|
||||||
meta.configs.getFields(['minimumTagLength', 'maximumTagLength'], function (err, data) {
|
meta.configs.getFields(['minimumTagLength', 'maximumTagLength'], function (err, data) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(data.minimumTagLength, 3);
|
assert.strictEqual(data.minimumTagLength, 3);
|
||||||
assert.equal(data.maximumTagLength, 15);
|
assert.strictEqual(data.maximumTagLength, 15);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -125,7 +125,7 @@ describe('meta', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set single config value', function (done) {
|
it('should set multiple config values', function (done) {
|
||||||
socketAdmin.config.set({ uid: fooUid }, { key: 'someKey', value: 'someValue' }, function (err) {
|
socketAdmin.config.set({ uid: fooUid }, { key: 'someKey', value: 'someValue' }, function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
meta.configs.getFields(['someKey'], function (err, data) {
|
meta.configs.getFields(['someKey'], function (err, data) {
|
||||||
@@ -141,7 +141,51 @@ describe('meta', function () {
|
|||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
meta.configs.getFields(['someField'], function (err, data) {
|
meta.configs.getFields(['someField'], function (err, data) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(data.someField, 'someValue');
|
assert.strictEqual(data.someField, 'someValue');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set numeric config value', function (done) {
|
||||||
|
meta.configs.set('numericField', 123, function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
meta.configs.getFields(['numericField'], function (err, data) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.strictEqual(data.numericField, 123);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set boolean config value', function (done) {
|
||||||
|
meta.configs.set('booleanField', true, function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
meta.configs.getFields(['booleanField'], function (err, data) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.strictEqual(data.booleanField, true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set boolean config value', function (done) {
|
||||||
|
meta.configs.set('booleanField', 'true', function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
meta.configs.getFields(['booleanField'], function (err, data) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.strictEqual(data.booleanField, true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set string config value', function (done) {
|
||||||
|
meta.configs.set('stringField', '123', function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
|
meta.configs.getFields(['stringField'], function (err, data) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.strictEqual(data.stringField, 123);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -173,7 +217,7 @@ describe('meta', function () {
|
|||||||
it('should not set config if not empty', function (done) {
|
it('should not set config if not empty', function (done) {
|
||||||
meta.configs.setOnEmpty({ someField1: 'foo' }, function (err) {
|
meta.configs.setOnEmpty({ someField1: 'foo' }, function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
db.getObjectField('config', 'someField1', function (err, value) {
|
meta.configs.get('someField1', function (err, value) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(value, 'someValue1');
|
assert.equal(value, 'someValue1');
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -224,6 +224,7 @@ function setupDefaultConfigs(meta, next) {
|
|||||||
|
|
||||||
var defaults = require(path.join(nconf.get('base_dir'), 'install/data/defaults.json'));
|
var defaults = require(path.join(nconf.get('base_dir'), 'install/data/defaults.json'));
|
||||||
defaults.eventLoopCheckEnabled = 0;
|
defaults.eventLoopCheckEnabled = 0;
|
||||||
|
defaults.minimumPasswordStrength = 0;
|
||||||
meta.configs.setOnEmpty(defaults, next);
|
meta.configs.setOnEmpty(defaults, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -364,7 +364,7 @@ describe('Post\'s', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should error if title is too long', function (done) {
|
it('should error if title is too long', function (done) {
|
||||||
var longTitle = new Array(parseInt(meta.config.maximumTitleLength, 10) + 2).join('a');
|
var longTitle = new Array(meta.config.maximumTitleLength + 2).join('a');
|
||||||
socketPosts.edit({ uid: voterUid }, { pid: pid, content: 'edited post content', title: longTitle }, function (err) {
|
socketPosts.edit({ uid: voterUid }, { pid: pid, content: 'edited post content', title: longTitle }, function (err) {
|
||||||
assert.equal(err.message, '[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]');
|
assert.equal(err.message, '[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]');
|
||||||
done();
|
done();
|
||||||
@@ -400,7 +400,7 @@ describe('Post\'s', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should error if content is too long', function (done) {
|
it('should error if content is too long', function (done) {
|
||||||
var longContent = new Array(parseInt(meta.config.maximumPostLength, 10) + 2).join('a');
|
var longContent = new Array(meta.config.maximumPostLength + 2).join('a');
|
||||||
socketPosts.edit({ uid: voterUid }, { pid: pid, content: longContent }, function (err) {
|
socketPosts.edit({ uid: voterUid }, { pid: pid, content: longContent }, function (err) {
|
||||||
assert.equal(err.message, '[[error:content-too-long, ' + meta.config.maximumPostLength + ']]');
|
assert.equal(err.message, '[[error:content-too-long, ' + meta.config.maximumPostLength + ']]');
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -552,7 +552,8 @@ describe('User', function () {
|
|||||||
assert(!userData.hasOwnProperty('another_secret'));
|
assert(!userData.hasOwnProperty('another_secret'));
|
||||||
assert(!userData.hasOwnProperty('password'));
|
assert(!userData.hasOwnProperty('password'));
|
||||||
assert(!userData.hasOwnProperty('rss_token'));
|
assert(!userData.hasOwnProperty('rss_token'));
|
||||||
assert.equal(userData.postcount, '123');
|
assert.strictEqual(userData.postcount, 123);
|
||||||
|
assert.strictEqual(userData.uid, testUid);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user