Skip to content

Node.js based forum software built for the modern web

closes #2975

barisusakli3d0b50a9b70e
diff --git a/src/user/settings.js b/src/user/settings.js
index 20c16fceb8..7c12cbfd00 100644
--- a/src/user/settings.js
+++ b/src/user/settings.js
@@ -55,13 +55,16 @@ module.exports = function(User) {
settings = data.settings;
+ var defaultTopicsPerPage = parseInt(meta.config.topicsPerPage, 10) || 20;
+ var defaultPostsPerPage = parseInt(meta.config.postsPerPage, 10) || 20;
+
settings.showemail = parseInt(settings.showemail, 10) === 1;
settings.showfullname = parseInt(settings.showfullname, 10) === 1;
settings.openOutgoingLinksInNewTab = parseInt(settings.openOutgoingLinksInNewTab, 10) === 1;
settings.dailyDigestFreq = settings.dailyDigestFreq || 'off';
settings.usePagination = (settings.usePagination === null || settings.usePagination === undefined) ? parseInt(meta.config.usePagination, 10) === 1 : parseInt(settings.usePagination, 10) === 1;
- settings.topicsPerPage = Math.min(settings.topicsPerPage ? parseInt(settings.topicsPerPage, 10) : parseInt(meta.config.topicsPerPage, 10) || 20, 20);
- settings.postsPerPage = Math.min(settings.postsPerPage ? parseInt(settings.postsPerPage, 10) : parseInt(meta.config.postsPerPage, 10) || 10, 20);
+ settings.topicsPerPage = Math.min(settings.topicsPerPage ? parseInt(settings.topicsPerPage, 10) : defaultTopicsPerPage, defaultTopicsPerPage);
+ settings.postsPerPage = Math.min(settings.postsPerPage ? parseInt(settings.postsPerPage, 10) : defaultPostsPerPage, defaultPostsPerPage);
settings.notificationSounds = parseInt(settings.notificationSounds, 10) === 1;
settings.userLang = settings.userLang || meta.config.defaultLang || 'en_GB';
settings.topicPostSort = settings.topicPostSort || meta.config.topicPostSort || 'oldest_to_newest';
@@ -78,7 +81,7 @@ module.exports = function(User) {
}
User.saveSettings = function(uid, data, callback) {
- if(!data.topicsPerPage || !data.postsPerPage || parseInt(data.topicsPerPage, 10) <= 0 || parseInt(data.postsPerPage, 10) <= 0) {
+ if (invalidPaginationSettings(data)) {
return callback(new Error('[[error:invalid-pagination-value]]'));
}
@@ -94,8 +97,8 @@ module.exports = function(User) {
openOutgoingLinksInNewTab: data.openOutgoingLinksInNewTab,
dailyDigestFreq: data.dailyDigestFreq || 'off',
usePagination: data.usePagination,
- topicsPerPage: Math.min(data.topicsPerPage, 20),
- postsPerPage: Math.min(data.postsPerPage, 20),
+ topicsPerPage: Math.min(data.topicsPerPage, parseInt(meta.config.topicsPerPage, 10) || 20),
+ postsPerPage: Math.min(data.postsPerPage, parseInt(meta.config.postsPerPage, 10) || 20),
notificationSounds: data.notificationSounds,
userLang: data.userLang || meta.config.defaultLang,
followTopicsOnCreate: data.followTopicsOnCreate,
@@ -116,6 +119,12 @@ module.exports = function(User) {
], callback);
};
+ function invalidPaginationSettings(data) {
+ return !data.topicsPerPage || !data.postsPerPage ||
+ parseInt(data.topicsPerPage, 10) <= 0 || parseInt(data.postsPerPage, 10) <= 0 ||
+ parseInt(data.topicsPerPage, 10) > meta.config.topicsPerPage || parseInt(data.postsPerPage, 10) > meta.config.postsPerPage;
+ }
+
function updateDigestSetting(uid, dailyDigestFreq, callback) {
async.waterfall([
function(next) {