diff --git a/public/vendor/bootbox/wrapper.js b/public/vendor/bootbox/wrapper.js index 8e54e0e7db..429fa9d6c6 100644 --- a/public/vendor/bootbox/wrapper.js +++ b/public/vendor/bootbox/wrapper.js @@ -22,8 +22,9 @@ require(['translator'], function (shim) { var translator = shim.Translator.create(); var dialog = bootbox.dialog; + var attrsToTranslate = ['placeholder', 'title', 'value']; bootbox.dialog = function (options) { - var show, $elem, nodes, text; + var show, $elem, nodes, text, attrNodes, attrText; show = options.show !== false; options.show = false; @@ -36,10 +37,27 @@ require(['translator'], function (shim) { return node.nodeValue; }).join(' || '); - translator.translate(text).then(function (translated) { + attrNodes = attrsToTranslate.reduce(function (prev, attr) { + return prev.concat(nodes.map.call($elem.find('[' + attr + '*="[["]'), function (el) { + return [attr, el]; + })); + }, []); + attrText = attrNodes.map(function (node) { + return node[1].getAttribute(node[0]); + }).join(' || '); + + Promise.all([ + translator.translate(text), + translator.translate(attrText), + ]).then(function (ref) { + var translated = ref[0]; + var translatedAttrs = ref[1]; translated.split(' || ').forEach(function (html, i) { $(nodes[i]).replaceWith(html); }); + translatedAttrs.split(' || ').forEach(function (text, i) { + attrNodes[i][1].setAttribute(attrNodes[i][0], text); + }); if (show) { $elem.modal('show'); } diff --git a/src/controllers/index.js b/src/controllers/index.js index e6b0d3753c..3b22c7ad1f 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -212,7 +212,9 @@ Controllers.registerInterstitial = function (req, res, next) { } if (!data.interstitials.length) { - return next(); + // No interstitials, redirect to home + delete req.session.registration; + return res.redirect('/'); } var renders = data.interstitials.map(function (interstitial) { diff --git a/src/database/mongo.js b/src/database/mongo.js index 2e09047da1..3a3331e900 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -47,7 +47,7 @@ module.helpers.mongo = require('./mongo/helpers'); module.init = function (callback) { - callback = callback || function () {}; + callback = callback || function () { }; var mongoClient; try { mongoClient = require('mongodb').MongoClient; @@ -111,38 +111,46 @@ if (err) { return callback(err); } - createSessionStore(); + callback(); }); } else { winston.warn('You have no mongo password setup!'); - createSessionStore(); - } - - function createSessionStore() { - var sessionStore; - if (nconf.get('redis')) { - sessionStore = require('connect-redis')(session); - var rdb = require('./redis'); - rdb.client = rdb.connect(); - - module.sessionStore = new sessionStore({ - client: rdb.client, - ttl: 60 * 60 * 24 * 14 - }); - } else if (nconf.get('mongo')) { - sessionStore = require('connect-mongo')(session); - module.sessionStore = new sessionStore({ - db: db - }); - } callback(); - } + } }); }; + module.initSessionStore = function (callback) { + var meta = require('../meta'); + var sessionStore; + + var ttlDays = 1000 * 60 * 60 * 24 * (parseInt(meta.config.loginDays, 10) || 0); + var ttlSeconds = 1000 * (parseInt(meta.config.loginSeconds, 10) || 0); + var ttl = ttlSeconds || ttlDays || 1209600000; // Default to 14 days + + if (nconf.get('redis')) { + sessionStore = require('connect-redis')(session); + var rdb = require('./redis'); + rdb.client = rdb.connect(); + + module.sessionStore = new sessionStore({ + client: rdb.client, + ttl: ttl + }); + } else if (nconf.get('mongo')) { + sessionStore = require('connect-mongo')(session); + module.sessionStore = new sessionStore({ + db: db, + ttl: ttl + }); + } + + callback(); + }; + module.createIndices = function (callback) { function createIndex(collection, index, options, callback) { - module.client.collection(collection).createIndex(index, options, callback); + module.client.collection(collection).createIndex(index, options, callback); } if (!module.client) { @@ -152,9 +160,9 @@ winston.info('[database] Checking database indices.'); async.series([ - async.apply(createIndex, 'objects', {_key: 1, score: -1}, {background: true}), - async.apply(createIndex, 'objects', {_key: 1, value: -1}, {background: true, unique: true, sparse: true}), - async.apply(createIndex, 'objects', {expireAt: 1}, {expireAfterSeconds: 0, background: true}) + async.apply(createIndex, 'objects', { _key: 1, score: -1 }, { background: true }), + async.apply(createIndex, 'objects', { _key: 1, value: -1 }, { background: true, unique: true, sparse: true }), + async.apply(createIndex, 'objects', { expireAt: 1 }, { expireAfterSeconds: 0, background: true }) ], function (err) { if (err) { winston.error('Error creating index ' + err.message); @@ -162,16 +170,16 @@ } winston.info('[database] Checking database indices done!'); callback(); - }); + }); }; module.checkCompatibility = function (callback) { var mongoPkg = require.main.require('./node_modules/mongodb/package.json'); - + if (semver.lt(mongoPkg.version, '2.0.0')) { return callback(new Error('The `mongodb` package is out-of-date, please run `./nodebb setup` again.')); } - + callback(); }; @@ -181,10 +189,10 @@ } async.parallel({ serverStatus: function (next) { - db.command({'serverStatus': 1}, next); + db.command({ 'serverStatus': 1 }, next); }, stats: function (next) { - db.command({'dbStats': 1}, next); + db.command({ 'dbStats': 1 }, next); }, listCollections: function (next) { db.listCollections().toArray(function (err, items) { @@ -239,4 +247,4 @@ db.close(); }; -}(exports)); +} (exports)); diff --git a/src/database/redis.js b/src/database/redis.js index f1c00a2316..8519b57bae 100644 --- a/src/database/redis.js +++ b/src/database/redis.js @@ -38,7 +38,6 @@ module.init = function (callback) { try { redis = require('redis'); - connectRedis = require('connect-redis')(session); } catch (err) { winston.error('Unable to initialize Redis! Is Redis installed? Error :' + err.message); process.exit(); @@ -48,11 +47,6 @@ module.client = redisClient; - module.sessionStore = new connectRedis({ - client: redisClient, - ttl: 60 * 60 * 24 * 14 - }); - require('./redis/main')(redisClient, module); require('./redis/hash')(redisClient, module); require('./redis/sets')(redisClient, module); @@ -64,6 +58,24 @@ } }; + module.initSessionStore = function (callback) { + var meta = require('../meta'); + var sessionStore = require('connect-redis')(session); + + var ttlDays = 1000 * 60 * 60 * 24 * (parseInt(meta.config.loginDays, 10) || 0); + var ttlSeconds = 1000 * (parseInt(meta.config.loginSeconds, 10) || 0); + var ttl = ttlSeconds || ttlDays || 1209600000; // Default to 14 days + + module.sessionStore = new sessionStore({ + client: module.client, + ttl: ttl + }); + + if (typeof callback === 'function') { + callback(); + } + }; + module.connect = function (options) { var redis_socket_or_host = nconf.get('redis:host'); var cxn; @@ -97,7 +109,7 @@ var dbIdx = parseInt(nconf.get('redis:database'), 10); if (dbIdx) { cxn.select(dbIdx, function (error) { - if(error) { + if (error) { winston.error("NodeBB could not connect to your Redis database. Redis returned the following error: " + error.message); process.exit(); } @@ -156,5 +168,5 @@ module.helpers = module.helpers || {}; module.helpers.redis = require('./redis/helpers'); -}(exports)); +} (exports)); diff --git a/src/emailer.js b/src/emailer.js index ce90839f12..4ccd35ed99 100644 --- a/src/emailer.js +++ b/src/emailer.js @@ -131,7 +131,7 @@ var fallbackTransport; data.from = data.from_name + '<' + data.from + '>'; delete data.from_name; - winston.verbose('[emailer] Sending email to uid ' + data.uid); + winston.verbose('[emailer] Sending email to uid ' + data.uid + ' (' + data.to + ')'); fallbackTransport.sendMail(data, function (err) { if (err) { winston.error(err); diff --git a/src/start.js b/src/start.js index f44b90643d..d314596036 100644 --- a/src/start.js +++ b/src/start.js @@ -40,6 +40,9 @@ start.start = function () { next(err); }); }, + function (next) { + db.initSessionStore(next); + }, function (next) { var webserver = require('./webserver'); require('./socket.io').init(webserver.server); diff --git a/src/views/admin/settings/user.tpl b/src/views/admin/settings/user.tpl index b10ed37da9..c7373fbeb7 100644 --- a/src/views/admin/settings/user.tpl +++ b/src/views/admin/settings/user.tpl @@ -20,7 +20,8 @@