meta config changes, refactors

v1.18.x
Baris Usakli 12 years ago
parent caa057ff4d
commit c647793512

@ -19,7 +19,8 @@
var fs = require('fs'), var fs = require('fs'),
winston = require('winston'), winston = require('winston'),
pkg = require('./package.json'), pkg = require('./package.json'),
url = require('url'); url = require('url'),
meta = require('./src/meta.js');
nconf = require('nconf'); nconf = require('nconf');
// Runtime environment // Runtime environment
@ -49,25 +50,20 @@ winston.info('This program comes with ABSOLUTELY NO WARRANTY.');
winston.info('This is free software, and you are welcome to redistribute it under certain conditions.'); winston.info('This is free software, and you are welcome to redistribute it under certain conditions.');
winston.info('==='); winston.info('===');
if(nconf.get('upgrade')) { if(nconf.get('upgrade')) {
require('./src/upgrade').upgrade(); meta.configs.init(function() {
require('./src/upgrade').upgrade();
});
} else if (!nconf.get('setup') && nconf.get('base_url')) { } else if (!nconf.get('setup') && nconf.get('base_url')) {
nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path') + '/'); nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path') + '/');
nconf.set('upload_url', nconf.get('url') + 'uploads/'); nconf.set('upload_url', nconf.get('url') + 'uploads/');
winston.info('Initializing NodeBB v' + pkg.version + ', on port ' + nconf.get('port') + ', using Redis store at ' + nconf.get('redis:host') + ':' + nconf.get('redis:port') + '.'); winston.info('Initializing NodeBB v' + pkg.version + ', on port ' + nconf.get('port') + ', using Redis store at ' + nconf.get('redis:host') + ':' + nconf.get('redis:port') + '.');
winston.info('Base Configuration OK.'); winston.info('Base Configuration OK.');
// TODO: Replace this with nconf-redis meta.configs.init(function() {
var meta = require('./src/meta.js');
global.config = {};
meta.config.get(function(config) {
for(c in config) {
if (config.hasOwnProperty(c)) {
global.config[c] = config[c];
}
}
var categories = require('./src/categories.js'), var categories = require('./src/categories.js'),
templates = require('./public/src/templates.js'), templates = require('./public/src/templates.js'),
@ -127,6 +123,7 @@ if(nconf.get('upgrade')) {
setup_categories(); setup_categories();
}(global.configuration)); }(global.configuration));
}); });
} else { } else {
// New install, ask setup questions // New install, ask setup questions
if (nconf.get('setup')) winston.info('NodeBB Setup Triggered via Command Line'); if (nconf.get('setup')) winston.info('NodeBB Setup Triggered via Command Line');

@ -85,10 +85,10 @@ var async = require('async'),
server_conf.base_url = protocol + '//' + host; server_conf.base_url = protocol + '//' + host;
server_conf.relative_path = relative_path; server_conf.relative_path = relative_path;
meta.config.set('postDelay', 10000); meta.configs.set('postDelay', 10000);
meta.config.set('minimumPostLength', 8); meta.configs.set('minimumPostLength', 8);
meta.config.set('minimumTitleLength', 3); meta.configs.set('minimumTitleLength', 3);
meta.config.set('imgurClientID', ''); meta.configs.set('imgurClientID', '');
install.save(server_conf, client_conf, callback); install.save(server_conf, client_conf, callback);
}); });

@ -25,13 +25,17 @@ var user = require('./user.js'),
}); });
} }
user.getUserFields(uid, ['password', 'banned'], function(userData) { user.getUserFields(uid, ['password', 'banned'], function(err, userData) {
if(err)
return next(err);
if(userData.banned && userData.banned === '1') { if(userData.banned && userData.banned === '1') {
return next({ return next({
status: "error", status: "error",
message: "user-banned" message: "user-banned"
}); });
} }
bcrypt.compare(password, userData.password, function(err, res) { bcrypt.compare(password, userData.password, function(err, res) {
if(err) { if(err) {
winston.err(err); winston.err(err);

@ -5,7 +5,14 @@ var utils = require('./../public/src/utils.js'),
fs = require('fs'); fs = require('fs');
(function(Meta) { (function(Meta) {
Meta.config = {
Meta.configs = {
init: function(callback) {
Meta.configs.get(function(config) {
Meta.config = config;
callback();
});
},
get: function(callback) { get: function(callback) {
RDB.hgetall('config', function(err, config) { RDB.hgetall('config', function(err, config) {
if (!err) { if (!err) {
@ -80,8 +87,8 @@ var utils = require('./../public/src/utils.js'),
}, function(err, values) { }, function(err, values) {
var title; var title;
if (err) title = global.config.title || 'NodeBB'; if (err) title = Meta.config.title || 'NodeBB';
else title = (values.title ? values.title + ' | ' : '') + (global.config.title || 'NodeBB'); else title = (values.title ? values.title + ' | ' : '') + (Meta.config.title || 'NodeBB');
callback(null, title, values.notifCount); callback(null, title, values.notifCount);
}); });
@ -110,4 +117,6 @@ var utils = require('./../public/src/utils.js'),
} else callback(null); } else callback(null);
} }
} }
}(exports)); }(exports));

@ -10,7 +10,8 @@ var RDB = require('./redis.js'),
reds = require('reds'), reds = require('reds'),
postSearch = reds.createSearch('nodebbpostsearch'), postSearch = reds.createSearch('nodebbpostsearch'),
topicSearch = reds.createSearch('nodebbtopicsearch'), topicSearch = reds.createSearch('nodebbtopicsearch'),
winston = require('winston'); winston = require('winston'),
meta = require('./meta.js');
(function(PostTools) { (function(PostTools) {
PostTools.isMain = function(pid, tid, callback) { PostTools.isMain = function(pid, tid, callback) {
@ -41,7 +42,7 @@ var RDB = require('./redis.js'),
function hasEnoughRep(next) { function hasEnoughRep(next) {
user.getUserField(uid, 'reputation', function(reputation) { user.getUserField(uid, 'reputation', function(reputation) {
next(null, reputation >= global.config['privileges:manage_content']); next(null, reputation >= meta.config['privileges:manage_content']);
}); });
} }

@ -11,6 +11,7 @@ var RDB = require('./redis.js'),
plugins = require('./plugins'), plugins = require('./plugins'),
reds = require('reds'), reds = require('reds'),
nconf = require('nconf'), nconf = require('nconf'),
meta = require('./meta.js'),
postSearch = reds.createSearch('nodebbpostsearch'), postSearch = reds.createSearch('nodebbpostsearch'),
winston = require('winston'); winston = require('winston');
@ -32,7 +33,9 @@ var RDB = require('./redis.js'),
} }
Posts.addUserInfoToPost = function(post, callback) { Posts.addUserInfoToPost = function(post, callback) {
user.getUserFields(post.uid, ['username', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned'], function(userData) { user.getUserFields(post.uid, ['username', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned'], function(err, userData) {
if(err)
return callback();
post.username = userData.username || 'anonymous'; post.username = userData.username || 'anonymous';
post.userslug = userData.userslug || ''; post.userslug = userData.userslug || '';
@ -43,7 +46,9 @@ var RDB = require('./redis.js'),
post.signature = postTools.markdownToHTML(userData.signature, true); post.signature = postTools.markdownToHTML(userData.signature, true);
if(post.editor !== '') { if(post.editor !== '') {
user.getUserFields(post.editor, ['username', 'userslug'], function(editorData) { user.getUserFields(post.editor, ['username', 'userslug'], function(err, editorData) {
if(err)
return callback();
post.editorname = editorData.username; post.editorname = editorData.username;
post.editorslug = editorData.userslug; post.editorslug = editorData.userslug;
callback(); callback();
@ -146,7 +151,12 @@ var RDB = require('./redis.js'),
postData.content = postTools.markdownToHTML(postData.content); postData.content = postTools.markdownToHTML(postData.content);
if(postData.uploadedImages) { if(postData.uploadedImages) {
postData.uploadedImages = JSON.parse(postData.uploadedImages); try {
postData.uploadedImages = JSON.parse(postData.uploadedImages);
} catch(err) {
postData.uploadedImages = [];
winston.err(err);
}
} else { } else {
postData.uploadedImages = []; postData.uploadedImages = [];
} }
@ -184,7 +194,7 @@ var RDB = require('./redis.js'),
type: 'error', type: 'error',
timeout: 2000, timeout: 2000,
title: 'Content too short', title: 'Content too short',
message: "Please enter a longer post. At least " + config.minimumPostLength + " characters.", message: "Please enter a longer post. At least " + meta.config.minimumPostLength + " characters.",
alert_id: 'post_error' alert_id: 'post_error'
}); });
} }
@ -192,7 +202,7 @@ var RDB = require('./redis.js'),
Posts.emitTooManyPostsAlert = function(socket) { Posts.emitTooManyPostsAlert = function(socket) {
socket.emit('event:alert', { socket.emit('event:alert', {
title: 'Too many posts!', title: 'Too many posts!',
message: 'You can only post every '+ config.postDelay/1000 + ' seconds.', message: 'You can only post every '+ meta.config.postDelay/1000 + ' seconds.',
type: 'error', type: 'error',
timeout: 2000 timeout: 2000
}); });
@ -203,13 +213,13 @@ var RDB = require('./redis.js'),
content = content.trim(); content = content.trim();
} }
if (!content || content.length < config.minimumPostLength) { if (!content || content.length < meta.config.minimumPostLength) {
callback(new Error('content-too-short'), null); callback(new Error('content-too-short'), null);
return; return;
} }
user.getUserField(uid, 'lastposttime', function(lastposttime) { user.getUserField(uid, 'lastposttime', function(lastposttime) {
if(Date.now() - lastposttime < config.postDelay) { if(Date.now() - lastposttime < meta.config.postDelay) {
callback(new Error('too-many-posts'), null); callback(new Error('too-many-posts'), null);
return; return;
} }
@ -264,7 +274,7 @@ var RDB = require('./redis.js'),
'editor': '', 'editor': '',
'edited': 0, 'edited': 0,
'deleted': 0, 'deleted': 0,
'uploadedImages': [], 'uploadedImages': '[]',
'fav_button_class': '', 'fav_button_class': '',
'fav_star_class': 'icon-star-empty', 'fav_star_class': 'icon-star-empty',
'show_banned': 'hide', 'show_banned': 'hide',
@ -310,7 +320,6 @@ var RDB = require('./redis.js'),
next(null, []); next(null, []);
} else { } else {
next(null, uploadedImages); next(null, uploadedImages);
Posts.setPostField(pid, 'uploadedImages', postData.uploadedImages);
} }
}); });
}, },
@ -321,6 +330,7 @@ var RDB = require('./redis.js'),
} }
}, function(err, results) { }, function(err, results) {
postData.uploadedImages = results.uploadedImages; postData.uploadedImages = results.uploadedImages;
Posts.setPostField(pid, 'uploadedImages', JSON.stringify(postData.uploadedImages));
postData.content = results.content; postData.content = results.content;
callback(postData); callback(postData);
}); });
@ -338,7 +348,7 @@ var RDB = require('./redis.js'),
function uploadPostImages(postData, images, callback) { function uploadPostImages(postData, images, callback) {
var imgur = require('./imgur'); var imgur = require('./imgur');
imgur.setClientID(config.imgurClientID); imgur.setClientID(meta.config.imgurClientID);
var uploadedImages = []; var uploadedImages = [];

@ -16,19 +16,14 @@ var user = require('./../user.js'),
}); });
app.get('/api/config', function(req, res, next) { app.get('/api/config', function(req, res, next) {
meta.config.getFields(['postDelay', 'minimumTitleLength', 'minimumPostLength', 'imgurClientID'], function(err, metaConfig) { var config = require('../../public/config.json');
if(err) return next();
var clientConfig = require('../../public/config.json');
for (var attrname in metaConfig) { config['postDelay'] = meta.config['postDelay'];
clientConfig[attrname] = metaConfig[attrname]; config['minimumTitleLength'] = meta.config['minimumTitleLength'];
} config['minimumPostLength'] = meta.config['minimumPostLength'];
config['imgurClientIDSet'] = !!meta.config['imgurClientID'];
clientConfig['imgurClientIDSet'] = !!clientConfig['imgurClientID'];
delete clientConfig['imgurClientID'];
res.json(200, clientConfig); res.json(200, config);
})
}); });
app.get('/api/home', function(req, res) { app.get('/api/home', function(req, res) {
@ -48,8 +43,8 @@ var user = require('./../user.js'),
} }
require('async').each(data.categories, iterator, function(err) { require('async').each(data.categories, iterator, function(err) {
data.motd_class = (config.show_motd === '1' || config.show_motd === undefined) ? '' : 'none'; data.motd_class = (meta.config.show_motd === '1' || meta.config.show_motd === undefined) ? '' : 'none';
data.motd = marked(config.motd || "# NodeBB <span class='hidden-phone'>v " + pkg.version + "</span>\nWelcome to NodeBB, the discussion platform of the future.\n\n<a target=\"_blank\" href=\"http://www.nodebb.org\" class=\"btn btn-large\"><i class=\"icon-comment\"></i><span class='hidden-phone'>&nbsp;Get NodeBB</span></a> <a target=\"_blank\" href=\"https://github.com/designcreateplay/NodeBB\" class=\"btn btn-large\"><i class=\"icon-github-alt\"></i><span class='hidden-phone'>&nbsp;Fork us on Github</span></a> <a target=\"_blank\" href=\"https://twitter.com/dcplabs\" class=\"btn btn-large\"><i class=\"icon-twitter\"></i><span class='hidden-phone'>&nbsp;@dcplabs</span></a>"); data.motd = marked(meta.config.motd || "# NodeBB <span class='hidden-phone'>v " + pkg.version + "</span>\nWelcome to NodeBB, the discussion platform of the future.\n\n<a target=\"_blank\" href=\"http://www.nodebb.org\" class=\"btn btn-large\"><i class=\"icon-comment\"></i><span class='hidden-phone'>&nbsp;Get NodeBB</span></a> <a target=\"_blank\" href=\"https://github.com/designcreateplay/NodeBB\" class=\"btn btn-large\"><i class=\"icon-github-alt\"></i><span class='hidden-phone'>&nbsp;Fork us on Github</span></a> <a target=\"_blank\" href=\"https://twitter.com/dcplabs\" class=\"btn btn-large\"><i class=\"icon-twitter\"></i><span class='hidden-phone'>&nbsp;@dcplabs</span></a>");
res.json(data); res.json(data);
}); });

@ -6,6 +6,7 @@
passportFacebook = require('passport-facebook').Strategy, passportFacebook = require('passport-facebook').Strategy,
login_strategies = [], login_strategies = [],
nconf = require('nconf'), nconf = require('nconf'),
meta = require('../meta'),
user = require('../user'), user = require('../user'),
winston = require('winston'), winston = require('winston'),
login_module = require('./../login.js'); login_module = require('./../login.js');
@ -17,10 +18,10 @@
}); });
})); }));
if (global.config['social:twitter:key'] && global.config['social:twitter:secret']) { if (meta.config['social:twitter:key'] && meta.config['social:twitter:secret']) {
passport.use(new passportTwitter({ passport.use(new passportTwitter({
consumerKey: global.config['social:twitter:key'], consumerKey: meta.config['social:twitter:key'],
consumerSecret: global.config['social:twitter:secret'], consumerSecret: meta.config['social:twitter:secret'],
callbackURL: nconf.get('url') + 'auth/twitter/callback' callbackURL: nconf.get('url') + 'auth/twitter/callback'
}, function(token, tokenSecret, profile, done) { }, function(token, tokenSecret, profile, done) {
login_module.loginViaTwitter(profile.id, profile.username, profile.photos, function(err, user) { login_module.loginViaTwitter(profile.id, profile.username, profile.photos, function(err, user) {
@ -32,10 +33,10 @@
login_strategies.push('twitter'); login_strategies.push('twitter');
} }
if (global.config['social:google:id'] && global.config['social:google:secret']) { if (meta.config['social:google:id'] && meta.config['social:google:secret']) {
passport.use(new passportGoogle({ passport.use(new passportGoogle({
clientID: global.config['social:google:id'], clientID: meta.config['social:google:id'],
clientSecret: global.config['social:google:secret'], clientSecret: meta.config['social:google:secret'],
callbackURL: nconf.get('url') + 'auth/google/callback' callbackURL: nconf.get('url') + 'auth/google/callback'
}, function(accessToken, refreshToken, profile, done) { }, function(accessToken, refreshToken, profile, done) {
login_module.loginViaGoogle(profile.id, profile.displayName, profile.emails[0].value, function(err, user) { login_module.loginViaGoogle(profile.id, profile.displayName, profile.emails[0].value, function(err, user) {
@ -47,10 +48,10 @@
login_strategies.push('google'); login_strategies.push('google');
} }
if (global.config['social:facebook:app_id'] && global.config['social:facebook:secret']) { if (meta.config['social:facebook:app_id'] && meta.config['social:facebook:secret']) {
passport.use(new passportFacebook({ passport.use(new passportFacebook({
clientID: global.config['social:facebook:app_id'], clientID: meta.config['social:facebook:app_id'],
clientSecret: global.config['social:facebook:secret'], clientSecret: meta.config['social:facebook:secret'],
callbackURL: nconf.get('url') + 'auth/facebook/callback' callbackURL: nconf.get('url') + 'auth/facebook/callback'
}, function(accessToken, refreshToken, profile, done) { }, function(accessToken, refreshToken, profile, done) {
login_module.loginViaFacebook(profile.id, profile.displayName, profile.emails[0].value, function(err, user) { login_module.loginViaFacebook(profile.id, profile.displayName, profile.emails[0].value, function(err, user) {

@ -281,7 +281,7 @@ var user = require('./../user.js'),
}); });
}); });
app.get('/api/users/:userslug/settings', function(req, res) { app.get('/api/users/:userslug/settings', function(req, res, next) {
var callerUID = req.user ? req.user.uid : 0; var callerUID = req.user ? req.user.uid : 0;
user.get_uid_by_userslug(req.params.userslug, function(uid) { user.get_uid_by_userslug(req.params.userslug, function(uid) {
@ -294,7 +294,10 @@ var user = require('./../user.js'),
res.json(403, { error: 'Not allowed!' }); res.json(403, { error: 'Not allowed!' });
return; return;
} }
user.getUserFields(uid, ['username','userslug','showemail'], function(userData) { user.getUserFields(uid, ['username','userslug','showemail'], function(err, userData) {
if(err)
return next(err);
if(userData) { if(userData) {
if(userData.showemail && userData.showemail === "1") if(userData.showemail && userData.showemail === "1")
userData.showemail = "checked"; userData.showemail = "checked";
@ -322,7 +325,10 @@ var user = require('./../user.js'),
return; return;
} }
user.getUserFields(uid, ['username','userslug'], function(userData) { user.getUserFields(uid, ['username','userslug'], function(err, userData) {
if(err)
return next(err);
if(userData) { if(userData) {
posts.getFavourites(uid, function(err, posts) { posts.getFavourites(uid, function(err, posts) {
if(err) if(err)

@ -7,7 +7,8 @@ var RDB = require('./redis.js'),
posts = require('./posts'), posts = require('./posts'),
reds = require('reds'), reds = require('reds'),
topicSearch = reds.createSearch('nodebbtopicsearch'), topicSearch = reds.createSearch('nodebbtopicsearch'),
winston = require('winston'); winston = require('winston'),
meta = require('./meta');
(function(ThreadTools) { (function(ThreadTools) {
@ -31,7 +32,7 @@ var RDB = require('./redis.js'),
function hasEnoughRep(next) { function hasEnoughRep(next) {
user.getUserField(uid, 'reputation', function(reputation) { user.getUserField(uid, 'reputation', function(reputation) {
next(null, reputation >= global.config['privileges:manage_topic']); next(null, reputation >= meta.config['privileges:manage_topic']);
}); });
} }
@ -110,12 +111,12 @@ var RDB = require('./redis.js'),
topics.setTopicField(tid, 'deleted', 0); topics.setTopicField(tid, 'deleted', 0);
ThreadTools.unlock(tid, uid); ThreadTools.unlock(tid, uid);
if (socket) { io.sockets.in('topic_' + tid).emit('event:topic_restored', {
io.sockets.in('topic_' + tid).emit('event:topic_restored', { tid: tid,
tid: tid, status: 'ok'
status: 'ok' });
});
if (socket) {
socket.emit('api:topic.restore', { socket.emit('api:topic.restore', {
status: 'ok', status: 'ok',
tid: tid tid: tid
@ -187,7 +188,7 @@ var RDB = require('./redis.js'),
multi.exec(function(err, result) { multi.exec(function(err, result) {
if (!err && result === 1) { if (!err && result[0] === 1 && result[1] === 1) {
topics.setTopicField(tid, 'cid', cid); topics.setTopicField(tid, 'cid', cid);

@ -211,9 +211,7 @@ marked.setOptions({
function getTopicInfo(topicData, callback) { function getTopicInfo(topicData, callback) {
function getUserInfo(next) { function getUserInfo(next) {
user.getUserFields(topicData.uid, ['username'], function(userData) { user.getUserFields(topicData.uid, ['username'], next);
next(null, userData);
});
} }
function hasReadTopic(next) { function hasReadTopic(next) {
@ -520,7 +518,10 @@ marked.setOptions({
if (!err) { if (!err) {
posts.getPostFields(pid, ['content', 'uid', 'timestamp'], function(postData) { posts.getPostFields(pid, ['content', 'uid', 'timestamp'], function(postData) {
user.getUserFields(postData.uid, ['username', 'picture'], function(userData) { user.getUserFields(postData.uid, ['username', 'picture'], function(err, userData) {
if(err)
return callback(err, null);
var stripped = postData.content, var stripped = postData.content,
timestamp = postData.timestamp; timestamp = postData.timestamp;
@ -546,7 +547,7 @@ marked.setOptions({
type: 'error', type: 'error',
timeout: 2000, timeout: 2000,
title: 'Title too short', title: 'Title too short',
message: "Please enter a longer title. At least " + config.minimumTitleLength + " characters.", message: "Please enter a longer title. At least " + meta.config.minimumTitleLength + " characters.",
alert_id: 'post_error' alert_id: 'post_error'
}); });
} }
@ -563,17 +564,17 @@ marked.setOptions({
if (uid === 0) { if (uid === 0) {
callback(new Error('not-logged-in'), null); callback(new Error('not-logged-in'), null);
return; return;
} else if(!title || title.length < config.minimumTitleLength) { } else if(!title || title.length < meta.config.minimumTitleLength) {
callback(new Error('title-too-short'), null); callback(new Error('title-too-short'), null);
return; return;
} else if (!content || content.length < config.miminumPostLength) { } else if (!content || content.length < meta.config.miminumPostLength) {
callback(new Error('content-too-short'), null); callback(new Error('content-too-short'), null);
return; return;
} }
user.getUserField(uid, 'lastposttime', function(lastposttime) { user.getUserField(uid, 'lastposttime', function(lastposttime) {
if(Date.now() - lastposttime < config.postDelay) { if(Date.now() - lastposttime < meta.config.postDelay) {
callback(new Error('too-many-posts'), null); callback(new Error('too-many-posts'), null);
return; return;
} }

@ -1,6 +1,7 @@
var RDB = require('./redis.js'), var RDB = require('./redis.js'),
async = require('async'), async = require('async'),
winston = require('winston'); winston = require('winston'),
user = require('./user');
function upgradeCategory(cid, callback) { function upgradeCategory(cid, callback) {
@ -36,7 +37,7 @@ function upgradeCategory(cid, callback) {
} }
function upgradeUser(uid, callback) { function upgradeUser(uid, callback) {
RDB.hmgetObject('user:' + uid, ['joindate', 'postcount', 'reputation'], function(err, userData) { user.getUserFields(uid, ['joindate', 'postcount', 'reputation'], function(err, userData) {
if(err) if(err)
return callback(err); return callback(err);
@ -46,7 +47,6 @@ function upgradeUser(uid, callback) {
callback(null); callback(null);
}); });
} }
exports.upgrade = function() { exports.upgrade = function() {

@ -2,7 +2,8 @@ var utils = require('./../public/src/utils.js'),
RDB = require('./redis.js'), RDB = require('./redis.js'),
crypto = require('crypto'), crypto = require('crypto'),
emailjs = require('emailjs'), emailjs = require('emailjs'),
emailjsServer = emailjs.server.connect(config.mailer), meta = require('./meta.js'),
emailjsServer = emailjs.server.connect(meta.config.mailer),
bcrypt = require('bcrypt'), bcrypt = require('bcrypt'),
marked = require('marked'), marked = require('marked'),
notifications = require('./notifications.js'), notifications = require('./notifications.js'),
@ -148,13 +149,7 @@ var utils = require('./../public/src/utils.js'),
} }
User.getUserFields = function(uid, fields, callback) { User.getUserFields = function(uid, fields, callback) {
RDB.hmgetObject('user:' + uid, fields, function(err, data) { RDB.hmgetObject('user:' + uid, fields, callback);
if(err === null) {
callback(data);
} else {
console.log(err);
}
});
} }
User.getMultipleUserFields = function(uids, fields, callback) { User.getMultipleUserFields = function(uids, fields, callback) {
@ -170,7 +165,9 @@ var utils = require('./../public/src/utils.js'),
}); });
function iterator(uid, callback) { function iterator(uid, callback) {
User.getUserFields(uid, fields, function(userData) { User.getUserFields(uid, fields, function(err, userData) {
if(err)
return callback(err);
returnData.push(userData); returnData.push(userData);
callback(null); callback(null);
}); });
@ -261,7 +258,10 @@ var utils = require('./../public/src/utils.js'),
if(field === 'email') { if(field === 'email') {
var gravatarpicture = User.createGravatarURLFromEmail(data[field]); var gravatarpicture = User.createGravatarURLFromEmail(data[field]);
User.setUserField(uid, 'gravatarpicture', gravatarpicture); User.setUserField(uid, 'gravatarpicture', gravatarpicture);
User.getUserFields(uid, ['email', 'picture', 'uploadedpicture'], function(userData) { User.getUserFields(uid, ['email', 'picture', 'uploadedpicture'], function(err, userData) {
if(err)
return callback(err);
RDB.del('email:' + userData['email'] + ':uid'); RDB.del('email:' + userData['email'] + ':uid');
RDB.set('email:' + data['email'] + ':uid', uid); RDB.set('email:' + data['email'] + ':uid', uid);
User.setUserField(uid, field, data[field]); User.setUserField(uid, field, data[field]);
@ -385,7 +385,7 @@ var utils = require('./../public/src/utils.js'),
return; return;
} }
bcrypt.genSalt(config.bcrypt_rounds, function(err, salt) { bcrypt.genSalt(nconf.get('bcrypt_rounds'), function(err, salt) {
bcrypt.hash(password, salt, function(err, hash) { bcrypt.hash(password, salt, function(err, hash) {
callback(hash); callback(hash);
}); });
@ -450,9 +450,9 @@ var utils = require('./../public/src/utils.js'),
} }
User.sendConfirmationEmail = function (email) { User.sendConfirmationEmail = function (email) {
if (global.config['email:host'] && global.config['email:port'] && global.config['email:from']) { if (meta.config['email:host'] && meta.config['email:port'] && meta.config['email:from']) {
var confirm_code = utils.generateUUID(), var confirm_code = utils.generateUUID(),
confirm_link = config.url + 'confirm/' + confirm_code, confirm_link = nconf.get('url') + 'confirm/' + confirm_code,
confirm_email = global.templates['emails/header'] + global.templates['emails/email_confirm'].parse({'CONFIRM_LINK': confirm_link}) + global.templates['emails/footer'], confirm_email = global.templates['emails/header'] + global.templates['emails/email_confirm'].parse({'CONFIRM_LINK': confirm_link}) + global.templates['emails/footer'],
confirm_email_plaintext = global.templates['emails/email_confirm_plaintext'].parse({ 'CONFIRM_LINK': confirm_link }); confirm_email_plaintext = global.templates['emails/email_confirm_plaintext'].parse({ 'CONFIRM_LINK': confirm_link });
@ -466,10 +466,10 @@ var utils = require('./../public/src/utils.js'),
RDB.set(confirm_key, email); RDB.set(confirm_key, email);
RDB.expire(confirm_key, expiry_time); RDB.expire(confirm_key, expiry_time);
// Send intro email w/ confirm code // Send intro email w/ confirm code
var message = emailjs.message.create({ var message = emailjs.message.create({
text: confirm_email_plaintext, text: confirm_email_plaintext,
from: config.mailer.from, from: meta.config.mailer.from,
to: email, to: email,
subject: '[NodeBB] Registration Email Verification', subject: '[NodeBB] Registration Email Verification',
attachment: [ attachment: [
@ -625,8 +625,9 @@ var utils = require('./../public/src/utils.js'),
RDB.zrevrange('users:joindate', 0, 0, function(err, uid) { RDB.zrevrange('users:joindate', 0, 0, function(err, uid) {
RDB.handle(err); RDB.handle(err);
User.getUserFields(uid, ['username', 'userslug'], function(userData) { User.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
socket.emit('user.latest', {userslug: userData.userslug, username: userData.username}); if(!err && userData)
socket.emit('user.latest', {userslug: userData.userslug, username: userData.username});
}); });
}); });
} }
@ -848,7 +849,7 @@ var utils = require('./../public/src/utils.js'),
var message = emailjs.message.create({ var message = emailjs.message.create({
text: reset_email_plaintext, text: reset_email_plaintext,
from: config.mailer?config.mailer.from:'localhost@example.org', from: meta.config.mailer?meta.config.mailer.from:'localhost@example.org',
to: email, to: email,
subject: 'Password Reset Requested', subject: 'Password Reset Requested',
attachment: [ attachment: [

@ -36,13 +36,13 @@ var express = require('express'),
{ name: 'viewport', content: 'width=device-width, initial-scale=1.0' }, { name: 'viewport', content: 'width=device-width, initial-scale=1.0' },
{ name: 'content-type', content: 'text/html; charset=UTF-8' }, { name: 'content-type', content: 'text/html; charset=UTF-8' },
{ name: 'apple-mobile-web-app-capable', content: 'yes' }, { name: 'apple-mobile-web-app-capable', content: 'yes' },
{ property: 'og:site_name', content: global.config.title || 'NodeBB' }, { property: 'og:site_name', content: meta.config.title || 'NodeBB' },
], ],
metaString = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || [])), metaString = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || [])),
templateValues = { templateValues = {
cssSrc: global.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css', cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
title: global.config['title'] || 'NodeBB', title: meta.config['title'] || 'NodeBB',
browserTitle: global.config['title'] || 'NodeBB', browserTitle: meta.config['title'] || 'NodeBB',
csrf: options.res.locals.csrf_token, csrf: options.res.locals.csrf_token,
relative_path: nconf.get('relative_path'), relative_path: nconf.get('relative_path'),
meta_tags: metaString meta_tags: metaString
@ -183,9 +183,9 @@ var express = require('express'),
req: req, req: req,
res: res, res: res,
metaTags: [ metaTags: [
{ name: "title", content: global.config.title || 'NodeBB' }, { name: "title", content: meta.config.title || 'NodeBB' },
{ name: "description", content: global.config.description || '' }, { name: "description", content: meta.config.description || '' },
{ property: 'og:title', content: 'Index | ' + (global.config.title || 'NodeBB') }, { property: 'og:title', content: 'Index | ' + (meta.config.title || 'NodeBB') },
{ property: "og:type", content: 'website' } { property: "og:type", content: 'website' }
] ]
}, next); }, next);
@ -241,7 +241,7 @@ var express = require('express'),
res: res, res: res,
metaTags: [ metaTags: [
{ name: "title", content: topicData.topic_name }, { name: "title", content: topicData.topic_name },
{ property: 'og:title', content: topicData.topic_name + ' | ' + (global.config.title || 'NodeBB') }, { property: 'og:title', content: topicData.topic_name + ' | ' + (meta.config.title || 'NodeBB') },
{ property: "og:type", content: 'article' }, { property: "og:type", content: 'article' },
{ property: "og:url", content: nconf.get('url') + 'topic/' + topicData.slug }, { property: "og:url", content: nconf.get('url') + 'topic/' + topicData.slug },
{ property: 'og:image', content: topicData.main_posts[0].picture }, { property: 'og:image', content: topicData.main_posts[0].picture },

@ -177,9 +177,11 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
socket.on('api:updateHeader', function(data) { socket.on('api:updateHeader', function(data) {
if(uid) { if(uid) {
user.getUserFields(uid, data.fields, function(fields) { user.getUserFields(uid, data.fields, function(err, fields) {
fields.uid = uid; if(!err && fields) {
socket.emit('api:updateHeader', fields); fields.uid = uid;
socket.emit('api:updateHeader', fields);
}
}); });
} }
else { else {
@ -261,10 +263,14 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
var type = data.type; var type = data.type;
function updateHeader() { function updateHeader() {
user.getUserFields(uid, ['picture'], function(fields) { user.getUserFields(uid, ['picture'], function(err, fields) {
fields.uid = uid; if(!err && fields) {
socket.emit('api:updateHeader', fields); fields.uid = uid;
callback(true); socket.emit('api:updateHeader', fields);
callback(true);
} else {
callback(false);
}
}); });
} }
@ -525,19 +531,19 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
}); });
socket.on('api:config.get', function(data) { socket.on('api:config.get', function(data) {
meta.config.get(function(config) { meta.configs.get(function(config) {
socket.emit('api:config.get', config); socket.emit('api:config.get', config);
}); });
}); });
socket.on('api:config.set', function(data) { socket.on('api:config.set', function(data) {
meta.config.set(data.key, data.value, function(err) { meta.configs.set(data.key, data.value, function(err) {
if (!err) socket.emit('api:config.set', { status: 'ok' }); if (!err) socket.emit('api:config.set', { status: 'ok' });
}); });
}); });
socket.on('api:config.remove', function(key) { socket.on('api:config.remove', function(key) {
meta.config.remove(key); meta.configs.remove(key);
}); });
socket.on('api:composer.push', function(data) { socket.on('api:composer.push', function(data) {
@ -555,14 +561,16 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
}); });
}); });
} else if (parseInt(data.cid) > 0) { } else if (parseInt(data.cid) > 0) {
user.getUserFields(uid, ['username', 'picture'], function(userData) { user.getUserFields(uid, ['username', 'picture'], function(err, userData) {
socket.emit('api:composer.push', { if(!err && userData) {
tid: 0, socket.emit('api:composer.push', {
cid: data.cid, tid: 0,
username: userData.username, cid: data.cid,
picture: userData.picture, username: userData.username,
title: undefined picture: userData.picture,
}); title: undefined
});
}
}); });
} else if (parseInt(data.pid) > 0) { } else if (parseInt(data.pid) > 0) {
async.parallel([ async.parallel([

Loading…
Cancel
Save