mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 03:01:08 +01:00
removed app.loadConfig
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
/*global io, templates, translator, ajaxify, utils, bootbox, RELATIVE_PATH*/
|
/*global io, templates, translator, ajaxify, utils, bootbox, RELATIVE_PATH, config*/
|
||||||
|
|
||||||
var socket,
|
var socket,
|
||||||
config,
|
|
||||||
app = {
|
app = {
|
||||||
'username': null,
|
'username': null,
|
||||||
'uid': null,
|
'uid': null,
|
||||||
@@ -17,6 +16,74 @@ var socket,
|
|||||||
var showWelcomeMessage = false;
|
var showWelcomeMessage = false;
|
||||||
var reconnecting = false;
|
var reconnecting = false;
|
||||||
|
|
||||||
|
function socketIOConnect() {
|
||||||
|
var ioParams = {
|
||||||
|
reconnectionAttempts: config.maxReconnectionAttempts,
|
||||||
|
reconnectionDelay : config.reconnectionDelay,
|
||||||
|
transports: config.socketioTransports,
|
||||||
|
path: config.relative_path + '/socket.io'
|
||||||
|
};
|
||||||
|
|
||||||
|
socket = io.connect(config.websocketAddress, ioParams);
|
||||||
|
reconnecting = false;
|
||||||
|
|
||||||
|
socket.on('event:connect', function (data) {
|
||||||
|
// TODO : deprecate in 0.7.0, use app.user
|
||||||
|
app.username = data.username;
|
||||||
|
app.userslug = data.userslug;
|
||||||
|
app.picture = data.picture;
|
||||||
|
app.uid = data.uid;
|
||||||
|
app.isAdmin = data.isAdmin;
|
||||||
|
|
||||||
|
app.user = data;
|
||||||
|
|
||||||
|
app.showLoginMessage();
|
||||||
|
app.replaceSelfLinks();
|
||||||
|
$(window).trigger('action:connected');
|
||||||
|
app.isConnected = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('connect', onSocketConnect);
|
||||||
|
|
||||||
|
socket.on('event:disconnect', function() {
|
||||||
|
$(window).trigger('action:disconnected');
|
||||||
|
app.isConnected = false;
|
||||||
|
socket.socket.connect();
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('reconnecting', function (data, attempt) {
|
||||||
|
if(attempt === parseInt(config.maxReconnectionAttempts, 10)) {
|
||||||
|
socket.socket.reconnectionAttempts = 0;
|
||||||
|
socket.socket.reconnectionDelay = config.reconnectionDelay;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
reconnecting = true;
|
||||||
|
var reconnectEl = $('#reconnect');
|
||||||
|
|
||||||
|
if (!reconnectEl.hasClass('active')) {
|
||||||
|
reconnectEl.html('<i class="fa fa-spinner fa-spin"></i>');
|
||||||
|
}
|
||||||
|
|
||||||
|
reconnectEl.addClass('active').removeClass("hide").tooltip({
|
||||||
|
placement: 'bottom'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('event:banned', function() {
|
||||||
|
app.alert({
|
||||||
|
title: '[[global:alert.banned]]',
|
||||||
|
message: '[[global:alert.banned.message]]',
|
||||||
|
type: 'danger',
|
||||||
|
timeout: 1000
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
window.location.href = config.relative_path + '/';
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function onSocketConnect(data) {
|
function onSocketConnect(data) {
|
||||||
if (reconnecting) {
|
if (reconnecting) {
|
||||||
var reconnectEl = $('#reconnect');
|
var reconnectEl = $('#reconnect');
|
||||||
@@ -64,109 +131,6 @@ var socket,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onConfigLoad(data) {
|
|
||||||
config = data;
|
|
||||||
|
|
||||||
exposeConfigToTemplates();
|
|
||||||
|
|
||||||
if(socket) {
|
|
||||||
socket.disconnect();
|
|
||||||
setTimeout(function() {
|
|
||||||
socket.connect();
|
|
||||||
}, 200);
|
|
||||||
} else {
|
|
||||||
var ioParams = {
|
|
||||||
reconnectionAttempts: config.maxReconnectionAttempts,
|
|
||||||
reconnectionDelay : config.reconnectionDelay,
|
|
||||||
transports: config.socketioTransports,
|
|
||||||
path: RELATIVE_PATH + '/socket.io'
|
|
||||||
};
|
|
||||||
|
|
||||||
socket = io.connect(config.websocketAddress, ioParams);
|
|
||||||
reconnecting = false;
|
|
||||||
|
|
||||||
socket.on('event:connect', function (data) {
|
|
||||||
// TODO : deprecate in 0.7.0, use app.user
|
|
||||||
app.username = data.username;
|
|
||||||
app.userslug = data.userslug;
|
|
||||||
app.picture = data.picture;
|
|
||||||
app.uid = data.uid;
|
|
||||||
app.isAdmin = data.isAdmin;
|
|
||||||
|
|
||||||
app.user = data;
|
|
||||||
|
|
||||||
templates.setGlobal('loggedIn', parseInt(data.uid, 10) !== 0);
|
|
||||||
|
|
||||||
app.showLoginMessage();
|
|
||||||
app.replaceSelfLinks();
|
|
||||||
$(window).trigger('action:connected');
|
|
||||||
app.isConnected = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('event:alert', function (data) {
|
|
||||||
app.alert(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('connect', onSocketConnect);
|
|
||||||
|
|
||||||
socket.on('event:disconnect', function() {
|
|
||||||
$(window).trigger('action:disconnected');
|
|
||||||
app.isConnected = false;
|
|
||||||
socket.socket.connect();
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('reconnecting', function (data, attempt) {
|
|
||||||
if(attempt === parseInt(config.maxReconnectionAttempts, 10)) {
|
|
||||||
socket.socket.reconnectionAttempts = 0;
|
|
||||||
socket.socket.reconnectionDelay = config.reconnectionDelay;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
reconnecting = true;
|
|
||||||
var reconnectEl = $('#reconnect');
|
|
||||||
|
|
||||||
if (!reconnectEl.hasClass('active')) {
|
|
||||||
reconnectEl.html('<i class="fa fa-spinner fa-spin"></i>');
|
|
||||||
}
|
|
||||||
|
|
||||||
reconnectEl.addClass('active').removeClass("hide").tooltip({
|
|
||||||
placement: 'bottom'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('event:banned', function() {
|
|
||||||
app.alert({
|
|
||||||
title: '[[global:alert.banned]]',
|
|
||||||
message: '[[global:alert.banned.message]]',
|
|
||||||
type: 'danger',
|
|
||||||
timeout: 1000
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
window.location.href = RELATIVE_PATH + '/';
|
|
||||||
}, 1000);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.cacheBuster = config['cache-buster'];
|
|
||||||
|
|
||||||
require(['csrf'], function(csrf) {
|
|
||||||
csrf.set(data.csrf_token);
|
|
||||||
});
|
|
||||||
|
|
||||||
bootbox.setDefaults({
|
|
||||||
locale: config.userLang
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
app.loadConfig = function() {
|
|
||||||
$.ajax({
|
|
||||||
url: RELATIVE_PATH + '/api/config',
|
|
||||||
success: onConfigLoad,
|
|
||||||
async: false
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
app.logout = function() {
|
app.logout = function() {
|
||||||
require(['csrf'], function(csrf) {
|
require(['csrf'], function(csrf) {
|
||||||
$.ajax(RELATIVE_PATH + '/logout', {
|
$.ajax(RELATIVE_PATH + '/logout', {
|
||||||
@@ -402,6 +366,7 @@ var socket,
|
|||||||
|
|
||||||
function exposeConfigToTemplates() {
|
function exposeConfigToTemplates() {
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
templates.setGlobal('loggedIn', config.loggedIn);
|
||||||
templates.setGlobal('relative_path', RELATIVE_PATH);
|
templates.setGlobal('relative_path', RELATIVE_PATH);
|
||||||
for(var key in config) {
|
for(var key in config) {
|
||||||
if (config.hasOwnProperty(key)) {
|
if (config.hasOwnProperty(key)) {
|
||||||
@@ -609,7 +574,20 @@ var socket,
|
|||||||
|
|
||||||
showWelcomeMessage = window.location.href.indexOf('loggedin') !== -1;
|
showWelcomeMessage = window.location.href.indexOf('loggedin') !== -1;
|
||||||
|
|
||||||
app.loadConfig();
|
exposeConfigToTemplates();
|
||||||
|
|
||||||
|
socketIOConnect();
|
||||||
|
|
||||||
|
app.cacheBuster = config['cache-buster'];
|
||||||
|
|
||||||
|
require(['csrf'], function(csrf) {
|
||||||
|
csrf.set(config.csrf_token);
|
||||||
|
});
|
||||||
|
|
||||||
|
bootbox.setDefaults({
|
||||||
|
locale: config.userLang
|
||||||
|
});
|
||||||
|
|
||||||
app.alternatingTitle('');
|
app.alternatingTitle('');
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/*global define, socket, app, ajaxify, config*/
|
||||||
|
|
||||||
define('forum/account/settings', ['forum/account/header'], function(header) {
|
define('forum/account/settings', ['forum/account/header'], function(header) {
|
||||||
var AccountSettings = {};
|
var AccountSettings = {};
|
||||||
|
|
||||||
@@ -26,13 +30,19 @@ define('forum/account/settings', ['forum/account/header'], function(header) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.emit('user.saveSettings', {uid: ajaxify.variables.get('theirid'), settings: settings}, function(err) {
|
socket.emit('user.saveSettings', {uid: ajaxify.variables.get('theirid'), settings: settings}, function(err, newSettings) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return app.alertError(err.message);
|
return app.alertError(err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.alertSuccess('[[success:settings-saved]]');
|
app.alertSuccess('[[success:settings-saved]]');
|
||||||
app.loadConfig();
|
|
||||||
|
for (var key in newSettings) {
|
||||||
|
if (newSettings.hasOwnProperty(key)) {
|
||||||
|
config[key] = newSettings[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (parseInt(app.uid, 10) === parseInt(ajaxify.variables.get('theirid'), 10)) {
|
if (parseInt(app.uid, 10) === parseInt(ajaxify.variables.get('theirid'), 10)) {
|
||||||
ajaxify.refresh();
|
ajaxify.refresh();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -216,6 +216,10 @@ middleware.renderHeader = function(req, res, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
plugins.fireHook('filter:header.build', custom_header, function(err, custom_header) {
|
plugins.fireHook('filter:header.build', custom_header, function(err, custom_header) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
var defaultMetaTags = [{
|
var defaultMetaTags = [{
|
||||||
name: 'viewport',
|
name: 'viewport',
|
||||||
content: 'width=device-width, initial-scale=1.0, user-scalable=no'
|
content: 'width=device-width, initial-scale=1.0, user-scalable=no'
|
||||||
@@ -260,6 +264,8 @@ middleware.renderHeader = function(req, res, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
templateValues.config = JSON.stringify(res.locals.config);
|
||||||
|
|
||||||
templateValues.metaTags = defaultMetaTags.concat(res.locals.metaTags || []).map(function(tag) {
|
templateValues.metaTags = defaultMetaTags.concat(res.locals.metaTags || []).map(function(tag) {
|
||||||
if(!tag || typeof tag.content !== 'string') {
|
if(!tag || typeof tag.content !== 'string') {
|
||||||
winston.warn('Invalid meta tag. ', tag);
|
winston.warn('Invalid meta tag. ', tag);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var meta = require('../meta'),
|
var async = require('async'),
|
||||||
|
meta = require('../meta'),
|
||||||
db = require('../database'),
|
db = require('../database'),
|
||||||
plugins = require('../plugins');
|
plugins = require('../plugins');
|
||||||
|
|
||||||
@@ -82,22 +83,30 @@ module.exports = function(User) {
|
|||||||
data.language = data.language || meta.config.defaultLang;
|
data.language = data.language || meta.config.defaultLang;
|
||||||
|
|
||||||
plugins.fireHook('action:user.saveSettings', {uid: uid, settings: data});
|
plugins.fireHook('action:user.saveSettings', {uid: uid, settings: data});
|
||||||
db.setObject('user:' + uid + ':settings', {
|
|
||||||
showemail: data.showemail,
|
async.waterfall([
|
||||||
showfullname: data.showfullname,
|
function(next) {
|
||||||
openOutgoingLinksInNewTab: data.openOutgoingLinksInNewTab,
|
db.setObject('user:' + uid + ':settings', {
|
||||||
dailyDigestFreq: data.dailyDigestFreq || 'off',
|
showemail: data.showemail,
|
||||||
usePagination: data.usePagination,
|
showfullname: data.showfullname,
|
||||||
topicsPerPage: Math.min(data.topicsPerPage, 20),
|
openOutgoingLinksInNewTab: data.openOutgoingLinksInNewTab,
|
||||||
postsPerPage: Math.min(data.postsPerPage, 20),
|
dailyDigestFreq: data.dailyDigestFreq || 'off',
|
||||||
notificationSounds: data.notificationSounds,
|
usePagination: data.usePagination,
|
||||||
language: data.language || meta.config.defaultLang,
|
topicsPerPage: Math.min(data.topicsPerPage, 20),
|
||||||
followTopicsOnCreate: data.followTopicsOnCreate,
|
postsPerPage: Math.min(data.postsPerPage, 20),
|
||||||
followTopicsOnReply: data.followTopicsOnReply,
|
notificationSounds: data.notificationSounds,
|
||||||
sendChatNotifications: data.sendChatNotifications,
|
language: data.language || meta.config.defaultLang,
|
||||||
restrictChat: data.restrictChat,
|
followTopicsOnCreate: data.followTopicsOnCreate,
|
||||||
topicSearchEnabled: data.topicSearchEnabled
|
followTopicsOnReply: data.followTopicsOnReply,
|
||||||
}, callback);
|
sendChatNotifications: data.sendChatNotifications,
|
||||||
|
restrictChat: data.restrictChat,
|
||||||
|
topicSearchEnabled: data.topicSearchEnabled
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
User.getSettings(uid, next);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
User.setSetting = function(uid, key, value, callback) {
|
User.setSetting = function(uid, key, value, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user