mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 07:25:46 +01:00
Merge branch 'master' of https://github.com/designcreateplay/NodeBB
This commit is contained in:
13
app.js
13
app.js
@@ -88,8 +88,11 @@
|
|||||||
websockets = require('./src/websockets.js'),
|
websockets = require('./src/websockets.js'),
|
||||||
posts = require('./src/posts.js'),
|
posts = require('./src/posts.js'),
|
||||||
plugins = require('./src/plugins'), // Don't remove this - plugins initializes itself
|
plugins = require('./src/plugins'), // Don't remove this - plugins initializes itself
|
||||||
Notifications = require('./src/notifications');
|
Notifications = require('./src/notifications'),
|
||||||
|
Upgrade = require('./src/upgrade');
|
||||||
|
|
||||||
|
Upgrade.check(function(schema_ok) {
|
||||||
|
if (schema_ok || nconf.get('check-schema') === false) {
|
||||||
websockets.init(SocketIO);
|
websockets.init(SocketIO);
|
||||||
|
|
||||||
global.templates = {};
|
global.templates = {};
|
||||||
@@ -112,6 +115,14 @@
|
|||||||
templates.ready(webserver.init);
|
templates.ready(webserver.init);
|
||||||
|
|
||||||
Notifications.init();
|
Notifications.init();
|
||||||
|
} else {
|
||||||
|
winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:');
|
||||||
|
winston.warn(' node app --upgrade');
|
||||||
|
winston.warn('To ignore this error (not recommended):');
|
||||||
|
winston.warn(' node app --no-check-schema')
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else if (nconf.get('setup') || !fs.existsSync(__dirname + '/config.json')) {
|
} else if (nconf.get('setup') || !fs.existsSync(__dirname + '/config.json')) {
|
||||||
// New install, ask setup questions
|
// New install, ask setup questions
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "nodebb",
|
"name": "nodebb",
|
||||||
"license": "GPLv3 or later",
|
"license": "GPLv3 or later",
|
||||||
"description": "NodeBB Forum",
|
"description": "NodeBB Forum",
|
||||||
"version": "0.0.7",
|
"version": "0.1.0",
|
||||||
"homepage": "http://www.nodebb.org",
|
"homepage": "http://www.nodebb.org",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -63,13 +63,14 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (setupVal && setupVal instanceof Object) {
|
if (setupVal && setupVal instanceof Object) {
|
||||||
if (setupVal['admin:username'] && setupVal['admin:password'] && setupVal['admin:email']) {
|
if (setupVal['admin:username'] && setupVal['admin:password'] && setupVal['admin:password:confirm'] && setupVal['admin:email']) {
|
||||||
install.values = setupVal;
|
install.values = setupVal;
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
winston.error('Required values are missing for automated setup:');
|
winston.error('Required values are missing for automated setup:');
|
||||||
if (!setupVal['admin:username']) winston.error(' admin:username');
|
if (!setupVal['admin:username']) winston.error(' admin:username');
|
||||||
if (!setupVal['admin:password']) winston.error(' admin:password');
|
if (!setupVal['admin:password']) winston.error(' admin:password');
|
||||||
|
if (!setupVal['admin:password:confirm']) winston.error(' admin:password:confirm');
|
||||||
if (!setupVal['admin:email']) winston.error(' admin:email');
|
if (!setupVal['admin:email']) winston.error(' admin:email');
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
@@ -277,18 +278,32 @@ var async = require('async'),
|
|||||||
description: 'Administrator email address',
|
description: 'Administrator email address',
|
||||||
pattern: /.+@.+/,
|
pattern: /.+@.+/,
|
||||||
required: true
|
required: true
|
||||||
}, {
|
}],
|
||||||
|
passwordQuestions = [{
|
||||||
name: 'password',
|
name: 'password',
|
||||||
description: 'Password',
|
description: 'Password',
|
||||||
required: true,
|
required: true,
|
||||||
hidden: true,
|
hidden: true,
|
||||||
type: 'string'
|
type: 'string'
|
||||||
|
}, {
|
||||||
|
name: 'password:confirm',
|
||||||
|
description: 'Confirm Password',
|
||||||
|
required: true,
|
||||||
|
hidden: true,
|
||||||
|
type: 'string'
|
||||||
}],
|
}],
|
||||||
success = function(err, results) {
|
success = function(err, results) {
|
||||||
if (!results) {
|
if (!results) {
|
||||||
return callback(new Error('aborted'));
|
return callback(new Error('aborted'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the passwords match
|
||||||
|
if (results['password:confirm'] !== results.password) {
|
||||||
|
winston.warn("Passwords did not match, please try again");
|
||||||
|
// Re-prompt password questions.
|
||||||
|
return retryPassword(results);
|
||||||
|
}
|
||||||
|
|
||||||
nconf.set('bcrypt_rounds', 12);
|
nconf.set('bcrypt_rounds', 12);
|
||||||
User.create(results.username, results.password, results.email, function (err, uid) {
|
User.create(results.username, results.password, results.email, function (err, uid) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -306,14 +321,33 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
retryPassword = function (originalResults) {
|
||||||
|
// Ask only the password questions
|
||||||
|
prompt.get(passwordQuestions, function (err, results) {
|
||||||
|
if (!results) {
|
||||||
|
return callback(new Error('aborted'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the original data with newly collected password
|
||||||
|
originalResults.password = results.password;
|
||||||
|
originalResults['password:confirm'] = results['password:confirm'];
|
||||||
|
|
||||||
|
// Send back to success to handle
|
||||||
|
success(err, originalResults);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Add the password questions
|
||||||
|
questions = questions.concat(passwordQuestions);
|
||||||
|
|
||||||
if (!install.values) prompt.get(questions, success);
|
if (!install.values) prompt.get(questions, success);
|
||||||
else {
|
else {
|
||||||
var results = {
|
var results = {
|
||||||
username: install.values['admin:username'],
|
username: install.values['admin:username'],
|
||||||
email: install.values['admin:email'],
|
email: install.values['admin:email'],
|
||||||
password: install.values['admin:password']
|
password: install.values['admin:password'],
|
||||||
|
'password:confirm': install.values['admin:password:confirm']
|
||||||
};
|
};
|
||||||
|
|
||||||
success(null, results);
|
success(null, results);
|
||||||
|
|||||||
@@ -191,11 +191,6 @@ var user = require('./../user.js'),
|
|||||||
is.on('end', function () {
|
is.on('end', function () {
|
||||||
fs.unlinkSync(tempPath);
|
fs.unlinkSync(tempPath);
|
||||||
|
|
||||||
var imageUrl = nconf.get('upload_url') + filename;
|
|
||||||
|
|
||||||
user.setUserField(uid, 'uploadedpicture', imageUrl);
|
|
||||||
user.setUserField(uid, 'picture', imageUrl);
|
|
||||||
|
|
||||||
require('node-imagemagick').crop({
|
require('node-imagemagick').crop({
|
||||||
srcPath: uploadPath,
|
srcPath: uploadPath,
|
||||||
dstPath: uploadPath,
|
dstPath: uploadPath,
|
||||||
@@ -204,8 +199,17 @@ var user = require('./../user.js'),
|
|||||||
}, function (err, stdout, stderr) {
|
}, function (err, stdout, stderr) {
|
||||||
if (err) {
|
if (err) {
|
||||||
winston.err(err);
|
winston.err(err);
|
||||||
|
res.send({
|
||||||
|
error: 'Invalid image file!'
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var imageUrl = nconf.get('upload_url') + filename;
|
||||||
|
|
||||||
|
user.setUserField(uid, 'uploadedpicture', imageUrl);
|
||||||
|
user.setUserField(uid, 'picture', imageUrl);
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
path: imageUrl
|
path: imageUrl
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,16 +1,38 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var RDB = require('./redis.js'),
|
var RDB = require('./redis.js'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
notifications = require('./notifications')
|
notifications = require('./notifications'),
|
||||||
Upgrade = {};
|
Upgrade = {},
|
||||||
|
|
||||||
|
schemaDate, thisSchemaDate;
|
||||||
|
|
||||||
|
Upgrade.check = function(callback) {
|
||||||
|
var latestSchema = new Date(2013, 10, 11).getTime();
|
||||||
|
|
||||||
|
RDB.get('schemaDate', function(err, value) {
|
||||||
|
if (parseInt(value, 10) >= latestSchema) {
|
||||||
|
callback(true);
|
||||||
|
} else {
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Upgrade.upgrade = function() {
|
Upgrade.upgrade = function() {
|
||||||
winston.info('Beginning Redis database schema update');
|
winston.info('Beginning Redis database schema update');
|
||||||
|
|
||||||
async.series([
|
async.series([
|
||||||
function(next) {
|
function(next) {
|
||||||
RDB.hget('notifications:1', 'score', function(err, score) {
|
RDB.get('schemaDate', function(err, value) {
|
||||||
if (score) {
|
schemaDate = value;
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
thisSchemaDate = new Date(2013, 9, 3).getTime();
|
||||||
|
if (schemaDate < thisSchemaDate) {
|
||||||
async.series([
|
async.series([
|
||||||
function(next) {
|
function(next) {
|
||||||
RDB.keys('uid:*:notifications:flag', function(err, keys) {
|
RDB.keys('uid:*:notifications:flag', function(err, keys) {
|
||||||
@@ -32,7 +54,11 @@ Upgrade.upgrade = function() {
|
|||||||
RDB.zrange(key, 0, -1, function(err, nids) {
|
RDB.zrange(key, 0, -1, function(err, nids) {
|
||||||
async.each(nids, function(nid, next) {
|
async.each(nids, function(nid, next) {
|
||||||
notifications.get(nid, null, function(notif_data) {
|
notifications.get(nid, null, function(notif_data) {
|
||||||
|
if (notif_data) {
|
||||||
RDB.zadd(key, notif_data.datetime, nid, next);
|
RDB.zadd(key, notif_data.datetime, nid, next);
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}, next);
|
}, next);
|
||||||
});
|
});
|
||||||
@@ -44,7 +70,10 @@ Upgrade.upgrade = function() {
|
|||||||
if (keys.length > 0) {
|
if (keys.length > 0) {
|
||||||
winston.info('[2013/10/03] Removing Notification Scores');
|
winston.info('[2013/10/03] Removing Notification Scores');
|
||||||
async.each(keys, function(key, next) {
|
async.each(keys, function(key, next) {
|
||||||
if (key === 'notifications:next_nid') return next();
|
if (key === 'notifications:next_nid') {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
RDB.hdel(key, 'score', next);
|
RDB.hdel(key, 'score', next);
|
||||||
}, next);
|
}, next);
|
||||||
} else {
|
} else {
|
||||||
@@ -58,13 +87,11 @@ Upgrade.upgrade = function() {
|
|||||||
winston.info('[2013/10/03] Updates to Notifications skipped.');
|
winston.info('[2013/10/03] Updates to Notifications skipped.');
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
RDB.exists('notifications', function(err, exists) {
|
thisSchemaDate = new Date(2013, 9, 23).getTime();
|
||||||
if (!exists) {
|
if (schemaDate < thisSchemaDate) {
|
||||||
RDB.keys('notifications:*', function(err, keys) {
|
RDB.keys('notifications:*', function(err, keys) {
|
||||||
var multi = RDB.multi();
|
|
||||||
|
|
||||||
keys = keys.filter(function(key) {
|
keys = keys.filter(function(key) {
|
||||||
if (key === 'notifications:next_nid') {
|
if (key === 'notifications:next_nid') {
|
||||||
@@ -77,17 +104,22 @@ Upgrade.upgrade = function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
winston.info('[2013/10/23] Adding existing notifications to set');
|
winston.info('[2013/10/23] Adding existing notifications to set');
|
||||||
RDB.sadd('notifications', keys, next);
|
|
||||||
|
if(keys && Array.isArray(keys)) {
|
||||||
|
async.each(keys, function(key, cb) {
|
||||||
|
RDB.sadd('notifications', key, cb);
|
||||||
|
}, next);
|
||||||
|
} else next();
|
||||||
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
winston.info('[2013/10/23] Updates to Notifications skipped.');
|
winston.info('[2013/10/23] Updates to Notifications skipped.');
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
RDB.hget('config', 'postDelay', function(err, postDelay) {
|
thisSchemaDate = new Date(2013, 10, 11).getTime();
|
||||||
if(parseInt(postDelay, 10) > 150) {
|
if (schemaDate < thisSchemaDate) {
|
||||||
RDB.hset('config', 'postDelay', 10, function(err, success) {
|
RDB.hset('config', 'postDelay', 10, function(err, success) {
|
||||||
winston.info('[2013/11/11] Updated postDelay to 10 seconds.');
|
winston.info('[2013/11/11] Updated postDelay to 10 seconds.');
|
||||||
next();
|
next();
|
||||||
@@ -96,15 +128,21 @@ Upgrade.upgrade = function() {
|
|||||||
winston.info('[2013/11/11] Update to postDelay skipped.');
|
winston.info('[2013/11/11] Update to postDelay skipped.');
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// Add new schema updates here
|
// Add new schema updates here
|
||||||
|
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 12!!!
|
||||||
], function(err) {
|
], function(err) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
winston.info('Redis schema update complete!');
|
RDB.set('schemaDate', thisSchemaDate, function(err) {
|
||||||
|
if (!err) {
|
||||||
|
winston.info('[upgrade] Redis schema update complete!');
|
||||||
process.exit();
|
process.exit();
|
||||||
} else {
|
} else {
|
||||||
winston.error('Errors were encountered while updating the NodeBB schema: ' + err.message);
|
winston.error('[upgrade] Could not update NodeBB schema date!');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
winston.error('[upgrade] Errors were encountered while updating the NodeBB schema: ' + err.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user