merging master to pull baris' latest fixes

v1.18.x
psychobunny 12 years ago
commit df15dceaef

@ -19,7 +19,8 @@
var fs = require('fs'),
winston = require('winston'),
pkg = require('./package.json'),
url = require('url');
url = require('url'),
meta = require('./src/meta.js');
nconf = require('nconf');
// Runtime environment
@ -49,28 +50,22 @@ 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('===');
if(nconf.get('upgrade')) {
meta.configs.init(function() {
require('./src/upgrade').upgrade();
});
} 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('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('Base Configuration OK.');
// TODO: Replace this with nconf-redis
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];
}
}
meta.configs.init(function() {
var categories = require('./src/categories.js'),
RDB = require('./src/redis.js'),
templates = require('./public/src/templates.js'),
webserver = require('./src/webserver.js'),
websockets = require('./src/websockets.js'),
@ -80,6 +75,7 @@ if(nconf.get('upgrade')) {
};
DEVELOPMENT = true;
RDB = require('./src/redis.js');
global.configuration = {};
global.templates = {};
@ -127,6 +123,7 @@ if(nconf.get('upgrade')) {
setup_categories();
}(global.configuration));
});
} else {
// New install, ask setup questions
if (nconf.get('setup')) winston.info('NodeBB Setup Triggered via Command Line');

@ -34,7 +34,8 @@
"cheerio": "~0.12.0",
"request": "~2.25.0",
"reds": "~0.2.4",
"winston": "~0.7.2"
"winston": "~0.7.2",
"nodebb-plugin-mentions": "~0.1.0"
},
"bugs": {
"url": "https://github.com/designcreateplay/NodeBB/issues"

@ -245,6 +245,7 @@ footer.footer {
color: #333;
margin-bottom: 10px;
cursor: pointer;
overflow:hidden;
p {
color: #333;
}

@ -77,10 +77,10 @@ var ajaxify = {};
app.scrollToPost(hash.substr(1));
});
}, url, template);
utils.refreshTitle(url);
}, url, template);
return true;
}
@ -94,9 +94,12 @@ var ajaxify = {};
// Enhancing all anchors to ajaxify...
$(document.body).on('click', 'a', function(e) {
if (this.href == window.location.href + "#") return;
if(this.href.slice(-1) === "#") return;
function hrefEmpty(href) {
return href == 'javascript:;' || href == window.location.href + "#" || href.slice(-1) === "#";
}
if(hrefEmpty(this.href)) return;
var url = this.href.replace(rootUrl +'/', '');

@ -218,7 +218,6 @@ var socket,
app.current_room = null;
app.enter_room = function(room) {
if(socket) {
if (app.current_room === room)
return;
@ -333,28 +332,47 @@ var socket,
app.infiniteLoaderActive = false;
if(data.posts.length) {
app.createNewPosts(data);
if(callback)
callback();
}
if(callback)
callback(data.posts);
});
}
app.scrollToPost = function(pid) {
if(!pid)
return;
var container = $(document.body),
scrollTo = $('#post_anchor_' + pid),
tid = $('#post-container').attr('data-tid');
while(!scrollTo.length) {
app.loadMorePosts(tid, function() {
scrollTo = $('#post_anchor_' + pid);
function animateScroll() {
$('body,html').animate({
scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop() - $('#header-menu').height()
});
}
container.animate({
scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop() - $('#header-menu').height()
if(!scrollTo.length && tid) {
var intervalID = setInterval(function() {
app.loadMorePosts(tid, function(posts) {
scrollTo = $('#post_anchor_' + pid);
if(tid && scrollTo.length) {
animateScroll();
}
if(!posts.length || scrollTo.length)
clearInterval(intervalID);
});
}, 100);
} else if(tid) {
animateScroll();
}
}
jQuery('document').ready(function() {

@ -26,17 +26,12 @@
if (thread_state.pinned === '1') set_pinned_state(true);
if (expose_tools === '1') {
var deleteThreadEl = document.getElementById('delete_thread'),
lockThreadEl = document.getElementById('lock_thread'),
pinThreadEl = document.getElementById('pin_thread'),
moveThreadEl = document.getElementById('move_thread'),
moveThreadModal = $('#move_thread_modal');
var moveThreadModal = $('#move_thread_modal');
adminTools.style.visibility = 'inherit';
// Add events to the thread tools
deleteThreadEl.addEventListener('click', function(e) {
e.preventDefault();
$('#delete_thread').on('click', function(e) {
if (thread_state.deleted !== '1') {
bootbox.confirm('Are you sure you want to delete this thread?', function(confirm) {
if (confirm) socket.emit('api:topic.delete', { tid: tid });
@ -46,30 +41,31 @@
if (confirm) socket.emit('api:topic.restore', { tid: tid });
});
}
}, false);
return false;
});
lockThreadEl.addEventListener('click', function(e) {
e.preventDefault();
$('#lock_thread').on('click', function(e) {
if (thread_state.locked !== '1') {
socket.emit('api:topic.lock', { tid: tid });
} else {
socket.emit('api:topic.unlock', { tid: tid });
}
}, false);
return false;
});
pinThreadEl.addEventListener('click', function(e) {
e.preventDefault();
$('#pin_thread').on('click', function(e) {
if (thread_state.pinned !== '1') {
socket.emit('api:topic.pin', { tid: tid });
} else {
socket.emit('api:topic.unpin', { tid: tid });
}
}, false);
return false;
});
moveThreadEl.addEventListener('click', function(e) {
e.preventDefault();
$('#move_thread').on('click', function(e) {
moveThreadModal.modal('show');
}, false);
return false;
});
moveThreadModal.on('shown', function() {
var loadingEl = document.getElementById('categories-loading');

@ -153,6 +153,11 @@
.addClass('badge-inverse')
}
});
},
isRelativeUrl: function(url) {
var firstChar = url.slice(0, 1);
return (firstChar === '.' || firstChar === '/');
}
}

@ -27,6 +27,8 @@
</script>
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="{relative_path}/src/utils.js"></script>
<link rel="stylesheet" type="text/css" href="{relative_path}/css/style.css" />
<link rel="stylesheet" type="text/css" href="{relative_path}/css/admin.css" />
</head>

@ -85,10 +85,10 @@ var async = require('async'),
server_conf.base_url = protocol + '//' + host;
server_conf.relative_path = relative_path;
meta.config.set('postDelay', 10000);
meta.config.set('minimumPostLength', 8);
meta.config.set('minimumTitleLength', 3);
meta.config.set('imgurClientID', '');
meta.configs.set('postDelay', 10000);
meta.configs.set('minimumPostLength', 8);
meta.configs.set('minimumTitleLength', 3);
meta.configs.set('imgurClientID', '');
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') {
return next({
status: "error",
message: "user-banned"
});
}
bcrypt.compare(password, userData.password, function(err, res) {
if(err) {
winston.err(err);

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

@ -20,28 +20,14 @@ var fs = require('fs'),
function(plugins, next) {
async.each(plugins, function(plugin) {
// TODO: Update this check to also check node_modules
var pluginPath = path.join(__dirname, '../plugins/', plugin);
fs.exists(pluginPath, function(exists) {
if (exists) {
fs.readFile(path.join(pluginPath, 'plugin.json'), function(err, data) {
if (err) return next(err);
var pluginData = JSON.parse(data);
_self.libraries[pluginData.id] = require(path.join(pluginPath, pluginData.library));
if (pluginData.hooks) {
for(var x=0,numHooks=pluginData.hooks.length;x<numHooks;x++) {
_self.registerHook(pluginData.id, pluginData.hooks[x]);
}
}
if (global.env === 'development') winston.info('[plugins] Loaded plugin: ' + pluginData.id);
next();
});
} else {
var pluginPath = path.join(__dirname, '../plugins/', plugin),
modulePath = path.join(__dirname, '../node_modules/', plugin);
if (fs.existsSync(pluginPath)) _self.loadPlugin(pluginPath, next);
else if (fs.existsSync(modulePath)) _self.loadPlugin(modulePath, next);
else {
if (global.env === 'development') winston.info('[plugins] Plugin \'' + plugin + '\' not found');
next(); // Ignore this plugin silently
}
})
}, next);
}
], function(err) {
@ -54,6 +40,24 @@ var fs = require('fs'),
});
},
initialized: false,
loadPlugin: function(pluginPath, callback) {
var _self = this;
fs.readFile(path.join(pluginPath, 'plugin.json'), function(err, data) {
if (err) return callback(err);
var pluginData = JSON.parse(data);
_self.libraries[pluginData.id] = require(path.join(pluginPath, pluginData.library));
if (pluginData.hooks) {
for(var x=0,numHooks=pluginData.hooks.length;x<numHooks;x++) {
_self.registerHook(pluginData.id, pluginData.hooks[x]);
}
}
if (global.env === 'development') winston.info('[plugins] Loaded plugin: ' + pluginData.id);
callback();
});
},
registerHook: function(id, data) {
/*
`data` is an object consisting of (* is required):
@ -66,7 +70,7 @@ var fs = require('fs'),
if (data.hook && data.method) {
_self.loadedHooks[data.hook] = _self.loadedHooks[data.hook] || [];
_self.loadedHooks[data.hook].push([id, data.method]);
_self.loadedHooks[data.hook].push([id, data.method, !!data.callbacked]);
if (global.env === 'development') winston.info('[plugins] Hook registered: ' + data.hook + ' will call ' + id);
} else return;
},
@ -84,7 +88,7 @@ var fs = require('fs'),
var returnVal = (Array.isArray(args) ? args[0] : args);
async.each(hookList, function(hookObj, next) {
if (hookObj.callbacked) {
if (hookObj[2]) {
_self.libraries[hookObj[0]][hookObj[1]](returnVal, function(err, afterVal) {
returnVal = afterVal;
next(err);
@ -95,7 +99,9 @@ var fs = require('fs'),
}
}, function(err) {
if (err) {
if (global.env === 'development') winston.info('[plugins] Problem executing hook: ' + hook);
if (global.env === 'development') {
winston.info('[plugins] Problem executing hook: ' + hook);
}
}
callback(returnVal);
@ -150,26 +156,49 @@ var fs = require('fs'),
showInstalled: function(callback) {
// TODO: Also check /node_modules
var _self = this;
moduleBasePath = path.join(__dirname, '../plugins');
localPluginPath = path.join(__dirname, '../plugins'),
npmPluginPath = path.join(__dirname, '../node_modules');
async.waterfall([
function(next) {
fs.readdir(moduleBasePath, next);
async.parallel([
function(next) {
fs.readdir(localPluginPath, next);
},
function(next) {
fs.readdir(npmPluginPath, next);
}
], function(err, dirs) {
if (err) return next(err);
dirs[0] = dirs[0].map(function(file) {
return path.join(localPluginPath, file);
}).filter(function(file) {
var stats = fs.statSync(file);
if (stats.isDirectory()) return true;
else return false;
});
dirs[1] = dirs[1].map(function(file) {
return path.join(npmPluginPath, file);
}).filter(function(file) {
var stats = fs.statSync(file);
if (stats.isDirectory() && file.substr(npmPluginPath.length+1, 14) === 'nodebb-plugin-') return true;
else return false;
});
next(err, dirs[0].concat(dirs[1]));
});
},
function(files, next) {
var plugins = [];
async.each(files, function(file, next) {
var modulePath = path.join(moduleBasePath, file),
configPath;
var configPath;
async.waterfall([
function(next) {
fs.stat(path.join(moduleBasePath, file), next);
},
function(stats, next) {
if (stats.isDirectory()) fs.readFile(path.join(modulePath, 'plugin.json'), next);
else next(new Error('not-a-directory'));
fs.readFile(path.join(file, 'plugin.json'), next);
},
function(configJSON, next) {
var config = JSON.parse(configJSON);

@ -10,7 +10,8 @@ var RDB = require('./redis.js'),
reds = require('reds'),
postSearch = reds.createSearch('nodebbpostsearch'),
topicSearch = reds.createSearch('nodebbtopicsearch'),
winston = require('winston');
winston = require('winston'),
meta = require('./meta.js');
(function(PostTools) {
PostTools.isMain = function(pid, tid, callback) {
@ -41,7 +42,7 @@ var RDB = require('./redis.js'),
function hasEnoughRep(next) {
user.getUserField(uid, 'reputation', function(reputation) {
next(null, reputation >= global.config['privileges:manage_content']);
next(null, reputation >= meta.config['privileges:manage_content']);
});
}
@ -175,7 +176,7 @@ var RDB = require('./redis.js'),
this.attr('rel', 'nofollow');
var href = this.attr('href');
if (href && !href.match(domain)) {
if (href && !href.match(domain) && !utils.isRelativeUrl(href)) {
this.attr('href', domain + 'outgoing?url=' + encodeURIComponent(href));
if (!isSignature) this.append(' <i class="icon-external-link"></i>');
}

@ -11,6 +11,7 @@ var RDB = require('./redis.js'),
plugins = require('./plugins'),
reds = require('reds'),
nconf = require('nconf'),
meta = require('./meta.js'),
postSearch = reds.createSearch('nodebbpostsearch'),
winston = require('winston');
@ -32,7 +33,9 @@ var RDB = require('./redis.js'),
}
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.userslug = userData.userslug || '';
@ -43,7 +46,9 @@ var RDB = require('./redis.js'),
post.signature = postTools.markdownToHTML(userData.signature, true);
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.editorslug = editorData.userslug;
callback();
@ -97,7 +102,10 @@ var RDB = require('./redis.js'),
Posts.getPostData = function(pid, callback) {
RDB.hgetall('post:' + pid, function(err, data) {
if(err === null) {
plugins.fireHook('filter:post.get', data.content, function(content) {
data.content = content;
callback(data);
});
}
else
console.log(err);
@ -143,7 +151,12 @@ var RDB = require('./redis.js'),
postData.content = postTools.markdownToHTML(postData.content);
if(postData.uploadedImages) {
try {
postData.uploadedImages = JSON.parse(postData.uploadedImages);
} catch(err) {
postData.uploadedImages = [];
winston.err(err);
}
} else {
postData.uploadedImages = [];
}
@ -181,7 +194,7 @@ var RDB = require('./redis.js'),
type: 'error',
timeout: 2000,
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'
});
}
@ -189,7 +202,7 @@ var RDB = require('./redis.js'),
Posts.emitTooManyPostsAlert = function(socket) {
socket.emit('event:alert', {
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',
timeout: 2000
});
@ -200,13 +213,13 @@ var RDB = require('./redis.js'),
content = content.trim();
}
if (!content || content.length < config.minimumPostLength) {
if (!content || content.length < meta.config.minimumPostLength) {
callback(new Error('content-too-short'), null);
return;
}
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);
return;
}
@ -224,22 +237,8 @@ var RDB = require('./redis.js'),
threadTools.notify_followers(tid, uid);
postData.content = postTools.markdownToHTML(postData.content);
postData.post_rep = 0;
postData.relativeTime = utils.relativeTime(postData.timestamp);
postData.fav_button_class = '';
postData.fav_star_class = 'icon-star-empty';
postData['edited-class'] = 'none';
postData.show_banned = 'hide';
postData.uploadedImages = JSON.parse(postData.uploadedImages);
var socketData = {
'posts' : [
postData
]
};
posts.addUserInfoToPost(socketData['posts'][0], function() {
Posts.addUserInfoToPost(postData, function() {
var socketData = { posts: [postData] };
io.sockets.in('topic_' + tid).emit('event:new_post', socketData);
io.sockets.in('recent_posts').emit('event:new_post', socketData);
});
@ -263,7 +262,7 @@ var RDB = require('./redis.js'),
RDB.incr('global:next_post_id', function(err, pid) {
RDB.handle(err);
plugins.fireHook('filter:save_post_content', content, function(content) {
plugins.fireHook('filter:post.save', content, function(content) {
var timestamp = Date.now(),
postData = {
'pid': pid,
@ -275,7 +274,14 @@ var RDB = require('./redis.js'),
'editor': '',
'edited': 0,
'deleted': 0,
'uploadedImages': ''
'uploadedImages': '[]',
'fav_button_class': '',
'fav_star_class': 'icon-star-empty',
'show_banned': 'hide',
'relativeTime': '0 seconds',
'post_rep': '0',
'edited-class': 'none',
'relativeEditTime': ''
};
RDB.hmset('post:' + pid, postData);
@ -306,17 +312,30 @@ var RDB = require('./redis.js'),
user.onNewPostMade(uid, tid, pid, timestamp);
async.parallel({
uploadedImages: function(next) {
uploadPostImages(postData, images, function(err, uploadedImages) {
if(err) {
winston.error('Uploading images failed!', err.stack);
next(null, []);
} else {
postData.uploadedImages = JSON.stringify(uploadedImages);
Posts.setPostField(pid, 'uploadedImages', postData.uploadedImages);
next(null, uploadedImages);
}
});
},
content: function(next) {
plugins.fireHook('filter:post.get', content, function(content) {
next(null, content);
});
}
}, function(err, results) {
postData.uploadedImages = results.uploadedImages;
Posts.setPostField(pid, 'uploadedImages', JSON.stringify(postData.uploadedImages));
postData.content = results.content;
callback(postData);
});
plugins.fireHook('action:save_post_content', [pid, content]);
plugins.fireHook('action:post.save', [pid, content]);
postSearch.index(content, pid);
});
@ -329,7 +348,7 @@ var RDB = require('./redis.js'),
function uploadPostImages(postData, images, callback) {
var imgur = require('./imgur');
imgur.setClientID(config.imgurClientID);
imgur.setClientID(meta.config.imgurClientID);
var uploadedImages = [];

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

@ -6,6 +6,7 @@
passportFacebook = require('passport-facebook').Strategy,
login_strategies = [],
nconf = require('nconf'),
meta = require('../meta'),
user = require('../user'),
winston = require('winston'),
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({
consumerKey: global.config['social:twitter:key'],
consumerSecret: global.config['social:twitter:secret'],
consumerKey: meta.config['social:twitter:key'],
consumerSecret: meta.config['social:twitter:secret'],
callbackURL: nconf.get('url') + 'auth/twitter/callback'
}, function(token, tokenSecret, profile, done) {
login_module.loginViaTwitter(profile.id, profile.username, profile.photos, function(err, user) {
@ -32,10 +33,10 @@
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({
clientID: global.config['social:google:id'],
clientSecret: global.config['social:google:secret'],
clientID: meta.config['social:google:id'],
clientSecret: meta.config['social:google:secret'],
callbackURL: nconf.get('url') + 'auth/google/callback'
}, function(accessToken, refreshToken, profile, done) {
login_module.loginViaGoogle(profile.id, profile.displayName, profile.emails[0].value, function(err, user) {
@ -47,10 +48,10 @@
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({
clientID: global.config['social:facebook:app_id'],
clientSecret: global.config['social:facebook:secret'],
clientID: meta.config['social:facebook:app_id'],
clientSecret: meta.config['social:facebook:secret'],
callbackURL: nconf.get('url') + 'auth/facebook/callback'
}, function(accessToken, refreshToken, profile, done) {
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;
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!' });
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.showemail && userData.showemail === "1")
userData.showemail = "checked";
@ -322,7 +325,10 @@ var user = require('./../user.js'),
return;
}
user.getUserFields(uid, ['username','userslug'], function(userData) {
user.getUserFields(uid, ['username','userslug'], function(err, userData) {
if(err)
return next(err);
if(userData) {
posts.getFavourites(uid, function(err, posts) {
if(err)

@ -7,7 +7,8 @@ var RDB = require('./redis.js'),
posts = require('./posts'),
reds = require('reds'),
topicSearch = reds.createSearch('nodebbtopicsearch'),
winston = require('winston');
winston = require('winston'),
meta = require('./meta');
(function(ThreadTools) {
@ -31,7 +32,7 @@ var RDB = require('./redis.js'),
function hasEnoughRep(next) {
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);
ThreadTools.unlock(tid, uid);
if (socket) {
io.sockets.in('topic_' + tid).emit('event:topic_restored', {
tid: tid,
status: 'ok'
});
if (socket) {
socket.emit('api:topic.restore', {
status: 'ok',
tid: tid
@ -187,7 +188,7 @@ var RDB = require('./redis.js'),
multi.exec(function(err, result) {
if (!err && result === 1) {
if (!err && result[0] === 1 && result[1] === 1) {
topics.setTopicField(tid, 'cid', cid);

@ -211,9 +211,7 @@ marked.setOptions({
function getTopicInfo(topicData, callback) {
function getUserInfo(next) {
user.getUserFields(topicData.uid, ['username'], function(userData) {
next(null, userData);
});
user.getUserFields(topicData.uid, ['username'], next);
}
function hasReadTopic(next) {
@ -520,7 +518,10 @@ marked.setOptions({
if (!err) {
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,
timestamp = postData.timestamp;
@ -546,7 +547,7 @@ marked.setOptions({
type: 'error',
timeout: 2000,
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'
});
}
@ -563,17 +564,17 @@ marked.setOptions({
if (uid === 0) {
callback(new Error('not-logged-in'), null);
return;
} else if(!title || title.length < config.minimumTitleLength) {
} else if(!title || title.length < meta.config.minimumTitleLength) {
callback(new Error('title-too-short'), null);
return;
} else if (!content || content.length < config.miminumPostLength) {
} else if (!content || content.length < meta.config.miminumPostLength) {
callback(new Error('content-too-short'), null);
return;
}
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);
return;
}

@ -1,6 +1,7 @@
var RDB = require('./redis.js'),
async = require('async'),
winston = require('winston');
winston = require('winston'),
user = require('./user');
function upgradeCategory(cid, callback) {
@ -36,7 +37,7 @@ function upgradeCategory(cid, 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)
return callback(err);
@ -46,7 +47,6 @@ function upgradeUser(uid, callback) {
callback(null);
});
}
exports.upgrade = function() {

@ -2,7 +2,8 @@ var utils = require('./../public/src/utils.js'),
RDB = require('./redis.js'),
crypto = require('crypto'),
emailjs = require('emailjs'),
emailjsServer = emailjs.server.connect(config.mailer),
meta = require('./meta.js'),
emailjsServer = emailjs.server.connect(meta.config.mailer),
bcrypt = require('bcrypt'),
marked = require('marked'),
notifications = require('./notifications.js'),
@ -148,13 +149,7 @@ var utils = require('./../public/src/utils.js'),
}
User.getUserFields = function(uid, fields, callback) {
RDB.hmgetObject('user:' + uid, fields, function(err, data) {
if(err === null) {
callback(data);
} else {
console.log(err);
}
});
RDB.hmgetObject('user:' + uid, fields, callback);
}
User.getMultipleUserFields = function(uids, fields, callback) {
@ -170,7 +165,9 @@ var utils = require('./../public/src/utils.js'),
});
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);
callback(null);
});
@ -261,7 +258,10 @@ var utils = require('./../public/src/utils.js'),
if(field === 'email') {
var gravatarpicture = User.createGravatarURLFromEmail(data[field]);
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.set('email:' + data['email'] + ':uid', uid);
User.setUserField(uid, field, data[field]);
@ -385,7 +385,7 @@ var utils = require('./../public/src/utils.js'),
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) {
callback(hash);
});
@ -450,9 +450,9 @@ var utils = require('./../public/src/utils.js'),
}
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(),
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_plaintext = global.templates['emails/email_confirm_plaintext'].parse({ 'CONFIRM_LINK': confirm_link });
@ -469,7 +469,7 @@ var utils = require('./../public/src/utils.js'),
// Send intro email w/ confirm code
var message = emailjs.message.create({
text: confirm_email_plaintext,
from: config.mailer.from,
from: meta.config.mailer.from,
to: email,
subject: '[NodeBB] Registration Email Verification',
attachment: [
@ -625,7 +625,8 @@ var utils = require('./../public/src/utils.js'),
RDB.zrevrange('users:joindate', 0, 0, function(err, uid) {
RDB.handle(err);
User.getUserFields(uid, ['username', 'userslug'], function(userData) {
User.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
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({
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,
subject: 'Password Reset Requested',
attachment: [

@ -36,13 +36,13 @@ var express = require('express'),
{ name: 'viewport', content: 'width=device-width, initial-scale=1.0' },
{ name: 'content-type', content: 'text/html; charset=UTF-8' },
{ 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 || [])),
templateValues = {
cssSrc: global.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
title: global.config['title'] || 'NodeBB',
browserTitle: global.config['title'] || 'NodeBB',
cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
title: meta.config['title'] || 'NodeBB',
browserTitle: meta.config['title'] || 'NodeBB',
csrf: options.res.locals.csrf_token,
relative_path: nconf.get('relative_path'),
meta_tags: metaString
@ -183,9 +183,9 @@ var express = require('express'),
req: req,
res: res,
metaTags: [
{ name: "title", content: global.config.title || 'NodeBB' },
{ name: "description", content: global.config.description || '' },
{ property: 'og:title', content: 'Index | ' + (global.config.title || 'NodeBB') },
{ name: "title", content: meta.config.title || 'NodeBB' },
{ name: "description", content: meta.config.description || '' },
{ property: 'og:title', content: 'Index | ' + (meta.config.title || 'NodeBB') },
{ property: "og:type", content: 'website' }
]
}, next);
@ -241,7 +241,7 @@ var express = require('express'),
res: res,
metaTags: [
{ 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:url", content: nconf.get('url') + 'topic/' + topicData.slug },
{ 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) {
if(uid) {
user.getUserFields(uid, data.fields, function(fields) {
user.getUserFields(uid, data.fields, function(err, fields) {
if(!err && fields) {
fields.uid = uid;
socket.emit('api:updateHeader', fields);
}
});
}
else {
@ -261,10 +263,14 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
var type = data.type;
function updateHeader() {
user.getUserFields(uid, ['picture'], function(fields) {
user.getUserFields(uid, ['picture'], function(err, fields) {
if(!err && fields) {
fields.uid = uid;
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) {
meta.config.get(function(config) {
meta.configs.get(function(config) {
socket.emit('api:config.get', config);
});
});
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' });
});
});
socket.on('api:config.remove', function(key) {
meta.config.remove(key);
meta.configs.remove(key);
});
socket.on('api:composer.push', function(data) {
@ -555,7 +561,8 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
});
});
} else if (parseInt(data.cid) > 0) {
user.getUserFields(uid, ['username', 'picture'], function(userData) {
user.getUserFields(uid, ['username', 'picture'], function(err, userData) {
if(!err && userData) {
socket.emit('api:composer.push', {
tid: 0,
cid: data.cid,
@ -563,6 +570,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
picture: userData.picture,
title: undefined
});
}
});
} else if (parseInt(data.pid) > 0) {
async.parallel([

Loading…
Cancel
Save