From d7df6c0b061cb27b0753dc7ef4a034a54caf6c83 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 10 Feb 2016 12:53:39 +0200 Subject: [PATCH] remove more from config --- install/data/defaults.json | 2 +- public/src/client/account/edit.js | 5 +++-- public/src/client/account/edit/password.js | 4 ++-- public/src/client/chats.js | 6 +++--- public/src/client/register.js | 6 +++--- public/src/client/reset_code.js | 13 ++++++----- public/src/modules/helpers.js | 4 ++-- src/controllers/accounts/chats.js | 1 + src/controllers/accounts/edit.js | 7 ++++++ src/controllers/api.js | 25 ++++++---------------- src/controllers/index.js | 7 +++--- src/middleware/header.js | 2 ++ 12 files changed, 41 insertions(+), 41 deletions(-) diff --git a/install/data/defaults.json b/install/data/defaults.json index 39a2226c5a..9c6a6f0c06 100644 --- a/install/data/defaults.json +++ b/install/data/defaults.json @@ -28,6 +28,6 @@ "maximumCoverImageSize": 2048, "profileImageDimension": 128, "requireEmailConfirmation": 0, - "profile:allowProfileImageUploads": 1, + "allowProfileImageUploads": 1, "teaserPost": "last" } diff --git a/public/src/client/account/edit.js b/public/src/client/account/edit.js index 1dd5795f4a..c60c974b96 100644 --- a/public/src/client/account/edit.js +++ b/public/src/client/account/edit.js @@ -80,7 +80,8 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'], } templates.parse('partials/modals/change_picture_modal', { pictures: pictures, - uploaded: !!ajaxify.data.uploadedpicture + uploaded: !!ajaxify.data.uploadedpicture, + allowProfileImageUploads: ajaxify.data.allowProfileImageUploads }, function(html) { translator.translate(html, function(html) { var modal = bootbox.dialog({ @@ -201,7 +202,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'], modal.find('[data-action="upload"]').on('click', function() { modal.modal('hide'); - uploader.open(config.relative_path + '/api/user/' + ajaxify.data.userslug + '/uploadpicture', {}, config.maximumProfileImageSize, function(imageUrlOnServer) { + uploader.open(config.relative_path + '/api/user/' + ajaxify.data.userslug + '/uploadpicture', {}, ajaxify.data.maximumProfileImageSize, function(imageUrlOnServer) { onUploadComplete(imageUrlOnServer); }); diff --git a/public/src/client/account/edit/password.js b/public/src/client/account/edit/password.js index 3e67045925..d5e500e7df 100644 --- a/public/src/client/account/edit/password.js +++ b/public/src/client/account/edit/password.js @@ -1,6 +1,6 @@ 'use strict'; -/* globals define, ajaxify, socket, app, config, utils */ +/* globals define, ajaxify, socket, app, utils */ define('forum/account/edit/password', ['forum/account/header', 'translator'], function(header, translator) { var AccountEditPassword = {}; @@ -21,7 +21,7 @@ define('forum/account/edit/password', ['forum/account/header', 'translator'], fu var passwordsmatch = false; function onPasswordChanged() { - if (password.val().length < config.minimumPasswordLength) { + if (password.val().length < ajaxify.data.minimumPasswordLength) { showError(password_notify, '[[user:change_password_error_length]]'); passwordvalid = false; } else if (!utils.isPasswordValid(password.val())) { diff --git a/public/src/client/chats.js b/public/src/client/chats.js index 9b35d735cb..fe2f9f9c77 100644 --- a/public/src/client/chats.js +++ b/public/src/client/chats.js @@ -426,10 +426,10 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', }; Chats.sendMessage = function(roomId, inputEl) { - var msg = inputEl.val(), - mid = inputEl.attr('data-mid'); + var msg = inputEl.val(); + var mid = inputEl.attr('data-mid'); - if (msg.length > config.maximumChatMessageLength) { + if (msg.length > ajaxify.data.maximumChatMessageLength) { return app.alertError('[[error:chat-message-too-long]]'); } diff --git a/public/src/client/register.js b/public/src/client/register.js index 3d0f943da9..92cf47da13 100644 --- a/public/src/client/register.js +++ b/public/src/client/register.js @@ -150,9 +150,9 @@ define('forum/register', ['csrf', 'translator'], function(csrf, translator) { var username_notify = $('#username-notify'); - if (username.length < config.minimumUsernameLength) { + if (username.length < ajaxify.data.minimumUsernameLength) { showError(username_notify, '[[error:username-too-short]]'); - } else if (username.length > config.maximumUsernameLength) { + } else if (username.length > ajaxify.data.maximumUsernameLength) { showError(username_notify, '[[error:username-too-long]]'); } else if (!utils.isUserNameValid(username) || !utils.slugify(username)) { showError(username_notify, '[[error:invalid-username]]'); @@ -179,7 +179,7 @@ define('forum/register', ['csrf', 'translator'], function(csrf, translator) { var password_notify = $('#password-notify'), password_confirm_notify = $('#password-confirm-notify'); - if (password.length < config.minimumPasswordLength) { + if (password.length < ajaxify.data.minimumPasswordLength) { showError(password_notify, '[[user:change_password_error_length]]'); } else if (!utils.isPasswordValid(password)) { showError(password_notify, '[[user:change_password_error]]'); diff --git a/public/src/client/reset_code.js b/public/src/client/reset_code.js index 678edf987a..2efd14b1a6 100644 --- a/public/src/client/reset_code.js +++ b/public/src/client/reset_code.js @@ -1,5 +1,5 @@ "use strict"; -/*globals define, app, ajaxify, socket, RELATIVE_PATH*/ +/*globals define, app, ajaxify, socket, config*/ define('forum/reset_code', function() { var ResetCode = {}; @@ -7,13 +7,12 @@ define('forum/reset_code', function() { ResetCode.init = function() { var reset_code = ajaxify.data.code; - var resetEl = $('#reset'), - password = $('#password'), - repeat = $('#repeat'), - noticeEl = $('#notice'); + var resetEl = $('#reset'); + var password = $('#password'); + var repeat = $('#repeat'); resetEl.on('click', function() { - if (password.val().length < config.minimumPasswordLength) { + if (password.val().length < ajaxify.data.minimumPasswordLength) { app.alertError('[[reset_password:password_too_short]]'); } else if (password.val() !== repeat.val()) { app.alertError('[[reset_password:passwords_do_not_match]]'); @@ -28,7 +27,7 @@ define('forum/reset_code', function() { return app.alertError(err.message); } - window.location.href = RELATIVE_PATH + '/login'; + window.location.href = config.relative_path + '/login'; }); } return false; diff --git a/public/src/modules/helpers.js b/public/src/modules/helpers.js index 989792dd3a..a585f0cc9a 100644 --- a/public/src/modules/helpers.js +++ b/public/src/modules/helpers.js @@ -24,11 +24,11 @@ } } - if (item.route.match('/users') && data.config.privateUserInfo && !data.config.loggedIn) { + if (item.route.match('/users') && data.privateUserInfo && !data.config.loggedIn) { return false; } - if (item.route.match('/tags') && data.config.privateTagListing && !data.config.loggedIn) { + if (item.route.match('/tags') && data.privateTagListing && !data.config.loggedIn) { return false; } diff --git a/src/controllers/accounts/chats.js b/src/controllers/accounts/chats.js index c30a4f0103..4af94c5521 100644 --- a/src/controllers/accounts/chats.js +++ b/src/controllers/accounts/chats.js @@ -66,6 +66,7 @@ chatsController.get = function(req, res, callback) { room.title = room.roomName; room.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[pages:chats]]', url: '/chats'}, {text: room.roomName}]); room.maximumUsersInChatRoom = parseInt(meta.config.maximumUsersInChatRoom, 10) || 0; + room.maximumChatMessageLength = parseInt(meta.config.maximumChatMessageLength, 10) || 1000; room.showUserInput = !room.maximumUsersInChatRoom || room.maximumUsersInChatRoom > 2; res.render('chats', room); diff --git a/src/controllers/accounts/edit.js b/src/controllers/accounts/edit.js index 44f4f0f426..98bbd2d2e3 100644 --- a/src/controllers/accounts/edit.js +++ b/src/controllers/accounts/edit.js @@ -21,6 +21,9 @@ editController.get = function(req, res, callback) { userData.maximumSignatureLength = parseInt(meta.config.maximumSignatureLength, 10) || 255; userData.maximumAboutMeLength = parseInt(meta.config.maximumAboutMeLength, 10) || 1000; + userData.maximumProfileImageSize = parseInt(meta.config.maximumProfileImageSize, 10); + userData.allowProfileImageUploads = parseInt(meta.config.allowProfileImageUploads) === 1; + userData.allowAccountDelete = parseInt(meta.config.allowAccountDelete, 10) === 1; userData.title = '[[pages:account/edit, ' + userData.username + ']]'; userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: '[[user:edit]]'}]); @@ -50,6 +53,10 @@ function renderRoute(name, req, res, next) { return next(); } + if (name === 'password') { + userData.minimumPasswordLength = parseInt(meta.config.minimumPasswordLength, 10); + } + userData.title = '[[pages:account/edit/' + name + ', ' + userData.username + ']]'; userData.breadcrumbs = helpers.buildBreadcrumbs([ {text: userData.username, url: '/user/' + userData.userslug}, diff --git a/src/controllers/api.js b/src/controllers/api.js index c00d2370c1..fb5ab709b6 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -28,9 +28,8 @@ apiController.getConfig = function(req, res, next) { } var config = {}; + config.environment = process.env.NODE_ENV; config.relative_path = nconf.get('relative_path'); - config.socketioTransports = nconf.get('socket.io:transports') || ['polling', 'websocket']; - config.websocketAddress = nconf.get('socket.io:address') || ''; config.version = nconf.get('version'); config.siteTitle = validator.escape(meta.config.title || meta.config.browserTitle || 'NodeBB'); config.browserTitle = validator.escape(meta.config.browserTitle || meta.config.title || 'NodeBB'); @@ -40,33 +39,24 @@ apiController.getConfig = function(req, res, next) { config.maximumTitleLength = meta.config.maximumTitleLength; config.minimumPostLength = meta.config.minimumPostLength; config.maximumPostLength = meta.config.maximumPostLength; - + config.minimumTagsPerTopic = meta.config.minimumTagsPerTopic || 0; + config.maximumTagsPerTopic = meta.config.maximumTagsPerTopic || 5; + config.minimumTagLength = meta.config.minimumTagLength || 3; + config.maximumTagLength = meta.config.maximumTagLength || 15; config.hasImageUploadPlugin = plugins.hasListeners('filter:uploadImage'); - config.maximumProfileImageSize = meta.config.maximumProfileImageSize; - config.minimumUsernameLength = meta.config.minimumUsernameLength; - config.maximumUsernameLength = meta.config.maximumUsernameLength; - config.minimumPasswordLength = meta.config.minimumPasswordLength; config.useOutgoingLinksPage = parseInt(meta.config.useOutgoingLinksPage, 10) === 1; config.allowGuestSearching = parseInt(meta.config.allowGuestSearching, 10) === 1; config.allowGuestUserSearching = parseInt(meta.config.allowGuestUserSearching, 10) === 1; config.allowGuestHandles = parseInt(meta.config.allowGuestHandles, 10) === 1; config.allowFileUploads = parseInt(meta.config.allowFileUploads, 10) === 1; - config.allowProfileImageUploads = parseInt(meta.config.allowProfileImageUploads) === 1; config.allowTopicsThumbnail = parseInt(meta.config.allowTopicsThumbnail, 10) === 1; - config.allowAccountDelete = parseInt(meta.config.allowAccountDelete, 10) === 1; - config.allowUserHomePage = parseInt(meta.config.allowUserHomePage, 10) === 1; - config.privateUserInfo = parseInt(meta.config.privateUserInfo, 10) === 1; - config.privateTagListing = parseInt(meta.config.privateTagListing, 10) === 1; config.usePagination = parseInt(meta.config.usePagination, 10) === 1; config.disableSocialButtons = parseInt(meta.config.disableSocialButtons, 10) === 1; config.disableChat = parseInt(meta.config.disableChat, 10) === 1; - config.maximumChatMessageLength = parseInt(meta.config.maximumChatMessageLength, 10) || 1000; + config.socketioTransports = nconf.get('socket.io:transports') || ['polling', 'websocket']; + config.websocketAddress = nconf.get('socket.io:address') || ''; config.maxReconnectionAttempts = meta.config.maxReconnectionAttempts || 5; config.reconnectionDelay = meta.config.reconnectionDelay || 1500; - config.minimumTagsPerTopic = meta.config.minimumTagsPerTopic || 0; - config.maximumTagsPerTopic = meta.config.maximumTagsPerTopic || 5; - config.minimumTagLength = meta.config.minimumTagLength || 3; - config.maximumTagLength = meta.config.maximumTagLength || 15; config.topicsPerPage = meta.config.topicsPerPage || 20; config.postsPerPage = meta.config.postsPerPage || 20; config.maximumFileSize = meta.config.maximumFileSize; @@ -74,7 +64,6 @@ apiController.getConfig = function(req, res, next) { config['theme:src'] = meta.config['theme:src']; config.defaultLang = meta.config.defaultLang || 'en_GB'; config.userLang = req.query.lang || config.defaultLang; - config.environment = process.env.NODE_ENV; config.loggedIn = !!req.user; config['cache-buster'] = meta.config['cache-buster'] || ''; config.requireEmailConfirmation = parseInt(meta.config.requireEmailConfirmation, 10) === 1; diff --git a/src/controllers/index.js b/src/controllers/index.js index a103c55d32..8ff28bd50e 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -77,6 +77,7 @@ Controllers.reset = function(req, res, next) { valid: valid, displayExpiryNotice: req.session.passwordExpired, code: req.params.code ? req.params.code : null, + minimumPasswordLength: parseInt(meta.config.minimumPasswordLength, 10), breadcrumbs: helpers.buildBreadcrumbs([{text: '[[reset_password:reset_password]]', url: '/reset'}, {text: '[[reset_password:update_password]]'}]), title: '[[pages:reset]]' }); @@ -137,9 +138,9 @@ Controllers.register = function(req, res, next) { data.authentication = loginStrategies; - data.minimumUsernameLength = meta.config.minimumUsernameLength; - data.maximumUsernameLength = meta.config.maximumUsernameLength; - data.minimumPasswordLength = meta.config.minimumPasswordLength; + data.minimumUsernameLength = parseInt(meta.config.minimumUsernameLength, 10); + data.maximumUsernameLength = parseInt(meta.config.maximumUsernameLength, 10); + data.minimumPasswordLength = parseInt(meta.config.minimumPasswordLength, 10); data.termsOfUse = tos.postData.content; data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[register:register]]'}]); data.regFormEntry = []; diff --git a/src/middleware/header.js b/src/middleware/header.js index 8ee165a9dc..c2149c16d1 100644 --- a/src/middleware/header.js +++ b/src/middleware/header.js @@ -130,6 +130,8 @@ module.exports = function(app, middleware) { templateValues.customJS = templateValues.useCustomJS ? meta.config.customJS : ''; templateValues.maintenanceHeader = parseInt(meta.config.maintenanceMode, 10) === 1 && !results.isAdmin; templateValues.defaultLang = meta.config.defaultLang || 'en_GB'; + templateValues.privateUserInfo = parseInt(meta.config.privateUserInfo, 10) === 1; + templateValues.privateTagListing = parseInt(meta.config.privateTagListing, 10) === 1; templateValues.template = {name: res.locals.template}; templateValues.template[res.locals.template] = true;