mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 23:45:45 +01:00
Merge remote-tracking branch 'origin'
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
[*.js, *.css, *.tpl]
|
||||
indent_style = tab
|
||||
17
.jsbeautifyrc
Normal file
17
.jsbeautifyrc
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"indent_size": 4,
|
||||
"indent_char": " ",
|
||||
"indent_level": 0,
|
||||
"indent_with_tabs": false,
|
||||
"preserve_newlines": true,
|
||||
"max_preserve_newlines": 10,
|
||||
"jslint_happy": false,
|
||||
"brace_style": "collapse",
|
||||
"keep_array_indentation": false,
|
||||
"keep_function_indentation": false,
|
||||
"space_before_conditional": true,
|
||||
"break_chained_methods": false,
|
||||
"eval_code": false,
|
||||
"unescape_strings": false,
|
||||
"wrap_line_length": 0
|
||||
}
|
||||
86
.jshintrc
Normal file
86
.jshintrc
Normal file
@@ -0,0 +1,86 @@
|
||||
{
|
||||
// JSHint Default Configuration File (as on JSHint website)
|
||||
// See http://jshint.com/docs/ for more details
|
||||
|
||||
"maxerr" : 50, // {int} Maximum error before stopping
|
||||
|
||||
// Enforcing
|
||||
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
|
||||
"camelcase" : false, // true: Identifiers must be in camelCase
|
||||
"curly" : true, // true: Require {} for every new block or scope
|
||||
"eqeqeq" : true, // true: Require triple equals (===) for comparison
|
||||
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
|
||||
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
|
||||
"indent" : 4, // {int} Number of spaces to use for indentation
|
||||
"latedef" : false, // true: Require variables/functions to be defined before being used
|
||||
"newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()`
|
||||
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
|
||||
"noempty" : true, // true: Prohibit use of empty blocks
|
||||
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
|
||||
"plusplus" : false, // true: Prohibit use of `++` & `--`
|
||||
"quotmark" : false, // Quotation mark consistency:
|
||||
// false : do nothing (default)
|
||||
// true : ensure whatever is used is consistent
|
||||
// "single" : require single quotes
|
||||
// "double" : require double quotes
|
||||
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
|
||||
"unused" : true, // true: Require all defined variables be used
|
||||
"strict" : true, // true: Requires all functions run in ES5 Strict Mode
|
||||
"trailing" : false, // true: Prohibit trailing whitespaces
|
||||
"maxparams" : false, // {int} Max number of formal params allowed per function
|
||||
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
|
||||
"maxstatements" : false, // {int} Max number statements per function
|
||||
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
|
||||
"maxlen" : false, // {int} Max number of characters per line
|
||||
|
||||
// Relaxing
|
||||
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
|
||||
"boss" : false, // true: Tolerate assignments where comparisons would be expected
|
||||
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
|
||||
"eqnull" : false, // true: Tolerate use of `== null`
|
||||
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
|
||||
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
|
||||
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
|
||||
// (ex: `for each`, multiple try/catch, function expression…)
|
||||
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
|
||||
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
|
||||
"funcscope" : false, // true: Tolerate defining variables inside control statements"
|
||||
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
|
||||
"iterator" : false, // true: Tolerate using the `__iterator__` property
|
||||
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
|
||||
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
|
||||
"laxcomma" : false, // true: Tolerate comma-first style coding
|
||||
"loopfunc" : false, // true: Tolerate functions being defined in loops
|
||||
"multistr" : false, // true: Tolerate multi-line strings
|
||||
"proto" : false, // true: Tolerate using the `__proto__` property
|
||||
"scripturl" : false, // true: Tolerate script-targeted URLs
|
||||
"smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment
|
||||
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
|
||||
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
|
||||
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
|
||||
"validthis" : false, // true: Tolerate using this in a non-constructor function
|
||||
|
||||
// Environments
|
||||
"browser" : true, // Web Browser (window, document, etc)
|
||||
"couch" : false, // CouchDB
|
||||
"devel" : true, // Development/debugging (alert, confirm, etc)
|
||||
"dojo" : false, // Dojo Toolkit
|
||||
"jquery" : true, // jQuery
|
||||
"mootools" : false, // MooTools
|
||||
"node" : true, // Node.js
|
||||
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
|
||||
"prototypejs" : false, // Prototype and Scriptaculous
|
||||
"rhino" : false, // Rhino
|
||||
"worker" : false, // Web Workers
|
||||
"wsh" : false, // Windows Scripting Host
|
||||
"yui" : false, // Yahoo User Interface
|
||||
|
||||
// Legacy
|
||||
"nomen" : false, // true: Prohibit dangling `_` in variables
|
||||
"onevar" : false, // true: Allow only one `var` statement per function
|
||||
"passfail" : false, // true: Stop on first error
|
||||
"white" : false, // true: Check against strict whitespace and indentation rules
|
||||
|
||||
// Custom Globals
|
||||
"globals" : {} // additional predefined global variables
|
||||
}
|
||||
8
app.js
8
app.js
@@ -53,7 +53,9 @@ winston.info('');
|
||||
|
||||
if (fs.existsSync(__dirname + '/config.json') && (!nconf.get('setup') && !nconf.get('upgrade'))) {
|
||||
// Load server-side config
|
||||
nconf.file({ file: __dirname + '/config.json'});
|
||||
nconf.file({
|
||||
file: __dirname + '/config.json'
|
||||
});
|
||||
|
||||
var meta = require('./src/meta.js');
|
||||
|
||||
@@ -93,7 +95,9 @@ if (fs.existsSync(__dirname + '/config.json') && (!nconf.get('setup') && !nconf.
|
||||
});
|
||||
|
||||
} else if (nconf.get('upgrade')) {
|
||||
nconf.file({ file: __dirname + '/config.json'});
|
||||
nconf.file({
|
||||
file: __dirname + '/config.json'
|
||||
});
|
||||
var meta = require('./src/meta.js');
|
||||
|
||||
meta.configs.init(function() {
|
||||
|
||||
@@ -43,7 +43,9 @@ var socket,
|
||||
}, 1000);
|
||||
reconnecting = false;
|
||||
reconnectTries = 0;
|
||||
socket.emit('api:updateHeader', { fields: ['username', 'picture', 'userslug'] });
|
||||
socket.emit('api:updateHeader', {
|
||||
fields: ['username', 'picture', 'userslug']
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -165,8 +167,7 @@ var socket,
|
||||
|
||||
clearTimeout(alert.attr('timeoutId'));
|
||||
startTimeout(alert, params.timeout);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
var div = document.createElement('div'),
|
||||
button = document.createElement('button'),
|
||||
strong = document.createElement('strong'),
|
||||
|
||||
@@ -26,7 +26,9 @@
|
||||
}
|
||||
|
||||
followBtn.on('click', function() {
|
||||
socket.emit('api:user.follow', {uid: theirid}, function(success) {
|
||||
socket.emit('api:user.follow', {
|
||||
uid: theirid
|
||||
}, function(success) {
|
||||
if (success) {
|
||||
followBtn.hide();
|
||||
unfollowBtn.show();
|
||||
@@ -39,7 +41,9 @@
|
||||
});
|
||||
|
||||
unfollowBtn.on('click', function() {
|
||||
socket.emit('api:user.unfollow', {uid: theirid}, function(success) {
|
||||
socket.emit('api:user.unfollow', {
|
||||
uid: theirid
|
||||
}, function(success) {
|
||||
if (success) {
|
||||
followBtn.show();
|
||||
unfollowBtn.hide();
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
var gravatarPicture = templates.get('gravatarpicture');
|
||||
var uploadedPicture = templates.get('uploadedpicture');
|
||||
|
||||
@@ -51,7 +49,9 @@ $(document).ready(function() {
|
||||
$('#upload-picture-modal').modal('hide');
|
||||
}, 750);
|
||||
|
||||
socket.emit('api:updateHeader', { fields: ['username', 'picture', 'userslug'] });
|
||||
socket.emit('api:updateHeader', {
|
||||
fields: ['username', 'picture', 'userslug']
|
||||
});
|
||||
success('File uploaded successfully!');
|
||||
}
|
||||
});
|
||||
@@ -131,15 +131,13 @@ $(document).ready(function() {
|
||||
if (gravatarPicture) {
|
||||
$('#user-gravatar-picture').attr('src', gravatarPicture);
|
||||
$('#gravatar-box').show();
|
||||
}
|
||||
else
|
||||
} else
|
||||
$('#gravatar-box').hide();
|
||||
|
||||
if (uploadedPicture) {
|
||||
$('#user-uploaded-picture').attr('src', uploadedPicture);
|
||||
$('#uploaded-box').show();
|
||||
}
|
||||
else
|
||||
} else
|
||||
$('#uploaded-box').hide();
|
||||
|
||||
|
||||
@@ -263,7 +261,10 @@ $(document).ready(function() {
|
||||
$('#changePasswordBtn').on('click', function() {
|
||||
|
||||
if (passwordvalid && passwordsmatch && currentPassword.val()) {
|
||||
socket.emit('api:user.changePassword', {'currentPassword': currentPassword.val(),'newPassword': password.val() }, function(err) {
|
||||
socket.emit('api:user.changePassword', {
|
||||
'currentPassword': currentPassword.val(),
|
||||
'newPassword': password.val()
|
||||
}, function(err) {
|
||||
|
||||
currentPassword.val('');
|
||||
password.val('');
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
$('#submitBtn').on('click', function() {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
|
||||
var modified_categories = {};
|
||||
|
||||
function modified(el) {
|
||||
var cid = $(el).parents('li').attr('data-cid');
|
||||
|
||||
modified_categories[cid] = modified_categories[cid] || {};
|
||||
modified_categories[cid][el.attr('data-name')] = el.val();
|
||||
modified_categories[cid][$(el).attr('data-name')] = $(el).val();
|
||||
}
|
||||
|
||||
function save() {
|
||||
@@ -73,7 +72,9 @@ jQuery('.blockclass').each(function() {
|
||||
timeout: 2000
|
||||
});
|
||||
|
||||
var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({categories:[data]});
|
||||
var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({
|
||||
categories: [data]
|
||||
});
|
||||
$('#entry-container').append(html);
|
||||
|
||||
$('#new-category-modal').modal('hide');
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
|
||||
|
||||
|
||||
var nodebb_admin = (function(nodebb_admin) {
|
||||
|
||||
nodebb_admin.config = undefined;
|
||||
@@ -63,7 +60,10 @@ var nodebb_admin = (function(nodebb_admin) {
|
||||
value = fields[x].value;
|
||||
}
|
||||
|
||||
socket.emit('api:config.set', { key: key, value: value });
|
||||
socket.emit('api:config.set', {
|
||||
key: key,
|
||||
value: value
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -119,4 +119,3 @@ var nodebb_admin = (function(nodebb_admin) {
|
||||
return nodebb_admin;
|
||||
|
||||
}(nodebb_admin || {}));
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
var nodebb_admin = (function(nodebb_admin) {
|
||||
|
||||
var themes = {};
|
||||
@@ -58,10 +56,12 @@ var nodebb_admin = (function(nodebb_admin) {
|
||||
cssSrc = parentEl.attr('data-css'),
|
||||
cssName = parentEl.attr('data-theme');
|
||||
socket.emit('api:config.set', {
|
||||
key: 'theme:id', value: 'bootswatch:' + cssName
|
||||
key: 'theme:id',
|
||||
value: 'bootswatch:' + cssName
|
||||
});
|
||||
socket.emit('api:config.set', {
|
||||
key: 'theme:src', value: cssSrc
|
||||
key: 'theme:src',
|
||||
value: cssSrc
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -9,16 +9,28 @@ $(document).ready(function() {
|
||||
|
||||
switch (action) {
|
||||
case 'pin':
|
||||
if (!$this.hasClass('active')) socket.emit('api:topic.pin', { tid: tid });
|
||||
else socket.emit('api:topic.unpin', { tid: tid });
|
||||
if (!$this.hasClass('active')) socket.emit('api:topic.pin', {
|
||||
tid: tid
|
||||
});
|
||||
else socket.emit('api:topic.unpin', {
|
||||
tid: tid
|
||||
});
|
||||
break;
|
||||
case 'lock':
|
||||
if (!$this.hasClass('active')) socket.emit('api:topic.lock', { tid: tid });
|
||||
else socket.emit('api:topic.unlock', { tid: tid });
|
||||
if (!$this.hasClass('active')) socket.emit('api:topic.lock', {
|
||||
tid: tid
|
||||
});
|
||||
else socket.emit('api:topic.unlock', {
|
||||
tid: tid
|
||||
});
|
||||
break;
|
||||
case 'delete':
|
||||
if (!$this.hasClass('active')) socket.emit('api:topic.delete', { tid: tid });
|
||||
else socket.emit('api:topic.restore', { tid: tid });
|
||||
if (!$this.hasClass('active')) socket.emit('api:topic.delete', {
|
||||
tid: tid
|
||||
});
|
||||
else socket.emit('api:topic.restore', {
|
||||
tid: tid
|
||||
});
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
(function() {
|
||||
|
||||
var yourid = templates.get('yourid');
|
||||
@@ -179,8 +178,7 @@
|
||||
.show()
|
||||
.addClass('label-danger')
|
||||
.removeClass('label-success');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$('#user-notfound-notify').html(data.length + ' user' + (data.length > 1 ? 's' : '') + ' found!')
|
||||
.show()
|
||||
.addClass('label-success')
|
||||
@@ -191,7 +189,9 @@
|
||||
});
|
||||
|
||||
function onUsersLoaded(users) {
|
||||
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({ users: users });
|
||||
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
|
||||
users: users
|
||||
});
|
||||
$('#users-container').append(html);
|
||||
updateUserButtons();
|
||||
}
|
||||
|
||||
@@ -36,7 +36,9 @@
|
||||
]);
|
||||
|
||||
function onNewTopic(data) {
|
||||
var html = templates.prepare(templates['category'].blocks['topics']).parse({ topics: [data] }),
|
||||
var html = templates.prepare(templates['category'].blocks['topics']).parse({
|
||||
topics: [data]
|
||||
}),
|
||||
topic = document.createElement('div'),
|
||||
container = document.getElementById('topics-container'),
|
||||
topics = document.querySelectorAll('#topics-container a'),
|
||||
@@ -98,7 +100,9 @@
|
||||
|
||||
function onTopicsLoaded(topics) {
|
||||
|
||||
var html = templates.prepare(templates['category'].blocks['topics']).parse({ topics: topics }),
|
||||
var html = templates.prepare(templates['category'].blocks['topics']).parse({
|
||||
topics: topics
|
||||
}),
|
||||
container = $('#topics-container');
|
||||
|
||||
jQuery('#topics-container, .category-sidebar').removeClass('hidden');
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
(function() {
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
$('.user-favourite-posts .topic-row').on('click', function() {
|
||||
ajaxify.go($(this).attr('topic-url'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -13,13 +13,14 @@
|
||||
|
||||
if (yourid !== theirid) {
|
||||
$('.unfollow-btn').hide();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$('.unfollow-btn').on('click', function() {
|
||||
var unfollowBtn = $(this);
|
||||
var followingUid = $(this).attr('followingUid');
|
||||
|
||||
socket.emit('api:user.unfollow', {uid: followingUid}, function(success) {
|
||||
socket.emit('api:user.unfollow', {
|
||||
uid: followingUid
|
||||
}, function(success) {
|
||||
var username = unfollowBtn.attr('data-username');
|
||||
if (success) {
|
||||
unfollowBtn.parent().remove();
|
||||
|
||||
@@ -22,7 +22,9 @@
|
||||
stats_online.innerHTML = data.users;
|
||||
});
|
||||
|
||||
socket.emit('api:updateHeader', { fields: ['username', 'picture', 'userslug'] });
|
||||
socket.emit('api:updateHeader', {
|
||||
fields: ['username', 'picture', 'userslug']
|
||||
});
|
||||
socket.on('api:updateHeader', function(data) {
|
||||
|
||||
jQuery('#search-button').on('click', function() {
|
||||
@@ -134,9 +136,15 @@
|
||||
notifList.addEventListener('click', function(e) {
|
||||
var target;
|
||||
switch (e.target.nodeName) {
|
||||
case 'SPAN': target = e.target.parentNode.parentNode; break;
|
||||
case 'A': target = e.target.parentNode; break;
|
||||
case 'li': target = e.target; break;
|
||||
case 'SPAN':
|
||||
target = e.target.parentNode.parentNode;
|
||||
break;
|
||||
case 'A':
|
||||
target = e.target.parentNode;
|
||||
break;
|
||||
case 'li':
|
||||
target = e.target;
|
||||
break;
|
||||
}
|
||||
if (target) {
|
||||
var nid = parseInt(target.getAttribute('data-nid'));
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
|
||||
|
||||
(function() {
|
||||
// Alternate Logins
|
||||
var altLoginEl = document.querySelector('.alt-logins');
|
||||
altLoginEl.addEventListener('click', function(e) {
|
||||
var target;
|
||||
switch (e.target.nodeName) {
|
||||
case 'LI': target = e.target; break;
|
||||
case 'I': target = e.target.parentNode; break;
|
||||
case 'LI':
|
||||
target = e.target;
|
||||
break;
|
||||
case 'I':
|
||||
target = e.target.parentNode;
|
||||
break;
|
||||
}
|
||||
if (target) {
|
||||
document.location.href = target.getAttribute('data-url');
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
'event:new_post'
|
||||
]);
|
||||
|
||||
var newTopicCount = 0, newPostCount = 0;
|
||||
var newTopicCount = 0,
|
||||
newPostCount = 0;
|
||||
|
||||
$('#new-topics-alert').on('click', function() {
|
||||
$(this).hide();
|
||||
@@ -50,7 +51,9 @@
|
||||
|
||||
function onTopicsLoaded(topics) {
|
||||
|
||||
var html = templates.prepare(templates['recent'].blocks['topics']).parse({ topics: topics }),
|
||||
var html = templates.prepare(templates['recent'].blocks['topics']).parse({
|
||||
topics: topics
|
||||
}),
|
||||
container = $('#topics-container');
|
||||
|
||||
$('#category-no-topics').remove();
|
||||
@@ -60,7 +63,9 @@
|
||||
|
||||
function loadMoreTopics() {
|
||||
loadingMoreTopics = true;
|
||||
socket.emit('api:topics.loadMoreRecentTopics', {after:$('#topics-container').children().length}, function(data) {
|
||||
socket.emit('api:topics.loadMoreRecentTopics', {
|
||||
after: $('#topics-container').children().length
|
||||
}, function(data) {
|
||||
if (data.topics && data.topics.length) {
|
||||
onTopicsLoaded(data.topics);
|
||||
}
|
||||
|
||||
@@ -36,9 +36,10 @@
|
||||
|
||||
if (!utils.isEmailValid(emailEl.val())) {
|
||||
showError(email_notify, 'Invalid email address.');
|
||||
}
|
||||
else
|
||||
socket.emit('user.email.exists', { email: emailEl.val() });
|
||||
} else
|
||||
socket.emit('user.email.exists', {
|
||||
email: emailEl.val()
|
||||
});
|
||||
}
|
||||
|
||||
emailEl.on('blur', function() {
|
||||
@@ -58,7 +59,9 @@
|
||||
} else if (!utils.isUserNameValid(username.val())) {
|
||||
showError(username_notify, 'Invalid username!');
|
||||
} else {
|
||||
socket.emit('user.exists', {username: username.val()});
|
||||
socket.emit('user.exists', {
|
||||
username: username.val()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
|
||||
document.getElementById('reset').onclick = function() {
|
||||
if (inputEl.value.length > 0 && inputEl.value.indexOf('@') !== -1) {
|
||||
socket.emit('user:reset.send', { email: inputEl.value });
|
||||
socket.emit('user:reset.send', {
|
||||
email: inputEl.value
|
||||
});
|
||||
} else {
|
||||
jQuery('#success').hide();
|
||||
jQuery(errorEl).show();
|
||||
|
||||
@@ -18,12 +18,17 @@
|
||||
noticeEl.querySelector('p').innerHTML = 'The two passwords you\'ve entered do not match.';
|
||||
noticeEl.style.display = 'block';
|
||||
} else {
|
||||
socket.emit('user:reset.commit', { code: reset_code, password: password.value });
|
||||
socket.emit('user:reset.commit', {
|
||||
code: reset_code,
|
||||
password: password.value
|
||||
});
|
||||
}
|
||||
}, false);
|
||||
|
||||
// Enable the form if the code is valid
|
||||
socket.emit('user:reset.valid', { code: reset_code });
|
||||
socket.emit('user:reset.valid', {
|
||||
code: reset_code
|
||||
});
|
||||
|
||||
|
||||
ajaxify.register_events(['user:reset.valid', 'user:reset.commit']);
|
||||
|
||||
@@ -34,11 +34,15 @@
|
||||
$('#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 });
|
||||
if (confirm) socket.emit('api:topic.delete', {
|
||||
tid: tid
|
||||
});
|
||||
});
|
||||
} else {
|
||||
bootbox.confirm('Are you sure you want to restore this thread?', function(confirm) {
|
||||
if (confirm) socket.emit('api:topic.restore', { tid: tid });
|
||||
if (confirm) socket.emit('api:topic.restore', {
|
||||
tid: tid
|
||||
});
|
||||
});
|
||||
}
|
||||
return false;
|
||||
@@ -46,18 +50,26 @@
|
||||
|
||||
$('#lock_thread').on('click', function(e) {
|
||||
if (thread_state.locked !== '1') {
|
||||
socket.emit('api:topic.lock', { tid: tid });
|
||||
socket.emit('api:topic.lock', {
|
||||
tid: tid
|
||||
});
|
||||
} else {
|
||||
socket.emit('api:topic.unlock', { tid: tid });
|
||||
socket.emit('api:topic.unlock', {
|
||||
tid: tid
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#pin_thread').on('click', function(e) {
|
||||
if (thread_state.pinned !== '1') {
|
||||
socket.emit('api:topic.pin', { tid: tid });
|
||||
socket.emit('api:topic.pin', {
|
||||
tid: tid
|
||||
});
|
||||
} else {
|
||||
socket.emit('api:topic.unpin', { tid: tid });
|
||||
socket.emit('api:topic.unpin', {
|
||||
tid: tid
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
@@ -132,7 +144,10 @@
|
||||
});
|
||||
}
|
||||
});
|
||||
socket.emit('api:topic.move', { tid: tid, cid: targetCid });
|
||||
socket.emit('api:topic.move', {
|
||||
tid: tid,
|
||||
cid: targetCid
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -242,7 +257,9 @@
|
||||
cmp.push(tid, null, null, quoted);
|
||||
});
|
||||
});
|
||||
socket.emit('api:posts.getRawPost', { pid: pid });
|
||||
socket.emit('api:posts.getRawPost', {
|
||||
pid: pid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -252,10 +269,15 @@
|
||||
|
||||
var element = $(this).find('i');
|
||||
if (element.attr('class') == 'icon-star-empty') {
|
||||
socket.emit('api:posts.favourite', {pid: pid, room_id: app.current_room});
|
||||
}
|
||||
else {
|
||||
socket.emit('api:posts.unfavourite', {pid: pid, room_id: app.current_room});
|
||||
socket.emit('api:posts.favourite', {
|
||||
pid: pid,
|
||||
room_id: app.current_room
|
||||
});
|
||||
} else {
|
||||
socket.emit('api:posts.unfavourite', {
|
||||
pid: pid,
|
||||
room_id: app.current_room
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -276,8 +298,12 @@
|
||||
|
||||
if (confirmDel) {
|
||||
deleteAction ?
|
||||
socket.emit('api:posts.delete', { pid: pid }) :
|
||||
socket.emit('api:posts.restore', { pid: pid });
|
||||
socket.emit('api:posts.delete', {
|
||||
pid: pid
|
||||
}) :
|
||||
socket.emit('api:posts.restore', {
|
||||
pid: pid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -377,17 +403,6 @@
|
||||
$(this).fadeIn(250);
|
||||
});
|
||||
|
||||
if(data.uploadedImages && data.uploadedImages.length) {
|
||||
$('#images_'+data.pid).html('');
|
||||
for(var i=0; i< data.uploadedImages.length; ++i) {
|
||||
var img = $('<i class="icon-picture icon-1"></i><a href="' + data.uploadedImages[i].url +'"> '+data.uploadedImages[i].name+'</a><br/>');
|
||||
$('#images_' + data.pid).append(img);
|
||||
}
|
||||
} else {
|
||||
$('#images_'+data.pid).html('');
|
||||
}
|
||||
|
||||
console.log('time to recreate images', data);
|
||||
});
|
||||
|
||||
socket.on('api:posts.favourite', function(data) {
|
||||
@@ -655,8 +670,7 @@
|
||||
var height = Math.floor(el.height());
|
||||
var elBottom = elTop + (height < 300 ? height : 300);
|
||||
|
||||
var inView = ((elBottom >= scrollTop) && (elTop <= scrollBottom)
|
||||
&& (elBottom <= scrollBottom) && (elTop >= scrollTop));
|
||||
var inView = ((elBottom >= scrollTop) && (elTop <= scrollBottom) && (elBottom <= scrollBottom) && (elTop >= scrollTop));
|
||||
|
||||
|
||||
if (inView) {
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
'event:new_post'
|
||||
]);
|
||||
|
||||
var newTopicCount = 0, newPostCount = 0;
|
||||
var newTopicCount = 0,
|
||||
newPostCount = 0;
|
||||
|
||||
$('#new-topics-alert').on('click', function() {
|
||||
$(this).hide();
|
||||
@@ -68,7 +69,9 @@
|
||||
|
||||
function onTopicsLoaded(topics) {
|
||||
|
||||
var html = templates.prepare(templates['unread'].blocks['topics']).parse({ topics: topics }),
|
||||
var html = templates.prepare(templates['unread'].blocks['topics']).parse({
|
||||
topics: topics
|
||||
}),
|
||||
container = $('#topics-container');
|
||||
|
||||
$('#category-no-topics').remove();
|
||||
@@ -78,7 +81,9 @@
|
||||
|
||||
function loadMoreTopics() {
|
||||
loadingMoreTopics = true;
|
||||
socket.emit('api:topics.loadMoreUnreadTopics', {after:parseInt($('#topics-container').attr('data-next-start'), 10)}, function(data) {
|
||||
socket.emit('api:topics.loadMoreUnreadTopics', {
|
||||
after: parseInt($('#topics-container').attr('data-next-start'), 10)
|
||||
}, function(data) {
|
||||
if (data.topics && data.topics.length) {
|
||||
onTopicsLoaded(data.topics);
|
||||
$('#topics-container').attr('data-next-start', data.nextStart);
|
||||
|
||||
@@ -67,8 +67,7 @@
|
||||
if (data && data.length === 0) {
|
||||
$('#user-notfound-notify').html('User not found!');
|
||||
$('#user-notfound-notify').parent().addClass('btn-warning label-warning');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$('#user-notfound-notify').html(data.length + ' user' + (data.length > 1 ? 's' : '') + ' found!');
|
||||
$('#user-notfound-notify').parent().addClass('btn-success label-success');
|
||||
}
|
||||
@@ -78,7 +77,9 @@
|
||||
|
||||
|
||||
function onUsersLoaded(users) {
|
||||
var html = templates.prepare(templates['users'].blocks['users']).parse({ users: users });
|
||||
var html = templates.prepare(templates['users'].blocks['users']).parse({
|
||||
users: users
|
||||
});
|
||||
$('#users-container').append(html);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,29 +7,33 @@ define(['taskbar'], function(taskbar) {
|
||||
postContainer: undefined,
|
||||
};
|
||||
|
||||
function createImageLabel(img, postImages) {
|
||||
var imageLabel = $('<span class="label label-primary">' + img.name +'</span>');
|
||||
var closeButton = $('<button class="close">×</button>');
|
||||
var uploadsInProgress = [];
|
||||
|
||||
closeButton.on('click', function(e) {
|
||||
function createImagePlaceholder(img) {
|
||||
var text = $('.post-window textarea').val(),
|
||||
textarea = $('.post-window textarea'),
|
||||
imgText = "";
|
||||
|
||||
imageLabel.remove();
|
||||
var index = postImages.indexOf(img);
|
||||
if(index !== -1) {
|
||||
postImages.splice(index, 1);
|
||||
}
|
||||
text += imgText;
|
||||
textarea.val(text + " ");
|
||||
uploadsInProgress.push(1);
|
||||
socket.emit("api:posts.uploadImage", img, function(err, data) {
|
||||
|
||||
var currentText = textarea.val();
|
||||
imgText = "";
|
||||
|
||||
if(!err)
|
||||
textarea.val(currentText.replace(imgText, ""));
|
||||
else
|
||||
textarea.val(currentText.replace(imgText, ""));
|
||||
uploadsInProgress.pop();
|
||||
});
|
||||
|
||||
imageLabel.append(closeButton);
|
||||
return imageLabel;
|
||||
}
|
||||
|
||||
function loadFile(file) {
|
||||
var reader = new FileReader(),
|
||||
dropDiv = $('.post-window .imagedrop'),
|
||||
imagelist = $('.post-window .imagelist'),
|
||||
uuid = dropDiv.parents('[data-uuid]').attr('data-uuid'),
|
||||
posts = composer.posts[uuid];
|
||||
uuid = dropDiv.parents('[data-uuid]').attr('data-uuid');
|
||||
|
||||
$(reader).on('loadend', function(e) {
|
||||
var bin = this.result;
|
||||
@@ -40,11 +44,8 @@ define(['taskbar'], function(taskbar) {
|
||||
data: bin
|
||||
};
|
||||
|
||||
posts.images.push(img);
|
||||
createImagePlaceholder(img);
|
||||
|
||||
var imageLabel = createImageLabel(img, posts.images);
|
||||
|
||||
imagelist.append(imageLabel);
|
||||
dropDiv.hide();
|
||||
});
|
||||
|
||||
@@ -89,7 +90,6 @@ define(['taskbar'], function(taskbar) {
|
||||
drop.on('drop', function(e) {
|
||||
e.preventDefault();
|
||||
var uuid = drop.parents('[data-uuid]').attr('data-uuid'),
|
||||
posts = composer.posts[uuid],
|
||||
dt = e.dataTransfer,
|
||||
files = dt.files;
|
||||
|
||||
@@ -121,7 +121,6 @@ define(['taskbar'], function(taskbar) {
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<textarea tabIndex="2"></textarea>' +
|
||||
'<div class="imagelist"></div>'+
|
||||
'<div class="imagedrop"><div>Drag and Drop Images Here</div></div>'+
|
||||
'<div class="btn-toolbar action-bar">' +
|
||||
'<div class="btn-group" style="float: right; margin-right: -8px">' +
|
||||
@@ -151,8 +150,7 @@ define(['taskbar'], function(taskbar) {
|
||||
cid: threadData.cid,
|
||||
pid: threadData.pid,
|
||||
title: threadData.title || '',
|
||||
body: threadData.body || '',
|
||||
images: threadData.uploadedImages || []
|
||||
body: threadData.body || ''
|
||||
};
|
||||
composer.load(uuid);
|
||||
} else {
|
||||
@@ -265,18 +263,6 @@ define(['taskbar'], function(taskbar) {
|
||||
});
|
||||
}
|
||||
|
||||
function createPostImages(images) {
|
||||
var imagelist = $(composer.postContainer).find('.imagelist');
|
||||
imagelist.empty();
|
||||
|
||||
if(images && images.length) {
|
||||
for(var i=0; i<images.length; ++i) {
|
||||
var imageLabel = createImageLabel(images[i], images);
|
||||
imagelist.append(imageLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
composer.load = function(post_uuid) {
|
||||
var post_data = composer.posts[post_uuid],
|
||||
titleEl = composer.postContainer.querySelector('input'),
|
||||
@@ -299,7 +285,6 @@ define(['taskbar'], function(taskbar) {
|
||||
}
|
||||
bodyEl.value = post_data.body;
|
||||
|
||||
createPostImages(post_data.images);
|
||||
|
||||
// Direct user focus to the correct element
|
||||
if ((parseInt(post_data.tid) || parseInt(post_data.pid)) > 0) {
|
||||
@@ -334,6 +319,16 @@ define(['taskbar'], function(taskbar) {
|
||||
titleEl.value = titleEl.value.trim();
|
||||
bodyEl.value = bodyEl.value.trim();
|
||||
|
||||
if(uploadsInProgress.length) {
|
||||
return app.alert({
|
||||
type: 'warning',
|
||||
timeout: 2000,
|
||||
title: 'Still uploading',
|
||||
message: "Please wait for uploads to complete.",
|
||||
alert_id: 'post_error'
|
||||
});
|
||||
}
|
||||
|
||||
if (titleEl.value.length < config.minimumTitleLength) {
|
||||
return app.alert({
|
||||
type: 'danger',
|
||||
@@ -359,21 +354,18 @@ define(['taskbar'], function(taskbar) {
|
||||
socket.emit('api:topics.post', {
|
||||
'title' : titleEl.value,
|
||||
'content' : bodyEl.value,
|
||||
'category_id' : postData.cid,
|
||||
images: composer.posts[post_uuid].images
|
||||
'category_id' : postData.cid
|
||||
});
|
||||
} else if (parseInt(postData.tid) > 0) {
|
||||
socket.emit('api:posts.reply', {
|
||||
'topic_id' : postData.tid,
|
||||
'content' : bodyEl.value,
|
||||
images: composer.posts[post_uuid].images
|
||||
'content' : bodyEl.value
|
||||
});
|
||||
} else if (parseInt(postData.pid) > 0) {
|
||||
socket.emit('api:posts.edit', {
|
||||
pid: postData.pid,
|
||||
content: bodyEl.value,
|
||||
title: titleEl.value,
|
||||
images: composer.posts[post_uuid].images
|
||||
title: titleEl.value
|
||||
});
|
||||
}
|
||||
|
||||
@@ -383,7 +375,6 @@ define(['taskbar'], function(taskbar) {
|
||||
composer.discard = function(post_uuid) {
|
||||
if (composer.posts[post_uuid]) {
|
||||
$(composer.postContainer).find('.imagedrop').hide();
|
||||
$(composer.postContainer).find('.imagelist').empty();
|
||||
delete composer.posts[post_uuid];
|
||||
composer.minimize();
|
||||
taskbar.discard('composer', post_uuid);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
(function(module) {
|
||||
|
||||
var config = {},
|
||||
@@ -252,7 +250,8 @@
|
||||
return template.replace(regex, block);
|
||||
}
|
||||
|
||||
var template = this.html, regex, block;
|
||||
var template = this.html,
|
||||
regex, block;
|
||||
|
||||
return (function parse(data, namespace, template) {
|
||||
if (!data || data.length == 0) {
|
||||
@@ -274,7 +273,9 @@
|
||||
continue;
|
||||
}
|
||||
|
||||
var numblocks = data[d].length - 1, i = 0, result = "";
|
||||
var numblocks = data[d].length - 1,
|
||||
i = 0,
|
||||
result = "";
|
||||
|
||||
do {
|
||||
result += parse(data[d][i], namespace, block);
|
||||
@@ -312,7 +313,8 @@
|
||||
templates.init();
|
||||
}
|
||||
|
||||
})('undefined' === typeof module ? {module:{exports:{}}} : module)
|
||||
|
||||
|
||||
|
||||
})('undefined' === typeof module ? {
|
||||
module: {
|
||||
exports: {}
|
||||
}
|
||||
} : module)
|
||||
@@ -10,7 +10,8 @@
|
||||
module.exports = utils = {
|
||||
generateUUID: function() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
|
||||
var r = Math.random() * 16 | 0,
|
||||
v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
},
|
||||
@@ -150,8 +151,7 @@
|
||||
badge
|
||||
.removeClass('badge-inverse')
|
||||
.addClass('badge-important')
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
badge
|
||||
.removeClass('badge-important')
|
||||
.addClass('badge-inverse')
|
||||
@@ -167,19 +167,27 @@
|
||||
|
||||
|
||||
if (!String.prototype.trim) {
|
||||
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');};
|
||||
String.prototype.trim = function() {
|
||||
return this.replace(/^\s+|\s+$/g, '');
|
||||
};
|
||||
}
|
||||
|
||||
if (!String.prototype.ltrim) {
|
||||
String.prototype.ltrim=function(){return this.replace(/^\s+/,'');};
|
||||
String.prototype.ltrim = function() {
|
||||
return this.replace(/^\s+/, '');
|
||||
};
|
||||
}
|
||||
|
||||
if (!String.prototype.rtrim) {
|
||||
String.prototype.rtrim=function(){return this.replace(/\s+$/,'');};
|
||||
String.prototype.rtrim = function() {
|
||||
return this.replace(/\s+$/, '');
|
||||
};
|
||||
}
|
||||
|
||||
if (!String.prototype.fulltrim) {
|
||||
String.prototype.fulltrim=function(){return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ');};
|
||||
String.prototype.fulltrim = function() {
|
||||
return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ');
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -187,4 +195,8 @@
|
||||
window.utils = module.exports;
|
||||
}
|
||||
|
||||
})('undefined' === typeof module ? {module:{exports:{}}} : module)
|
||||
})('undefined' === typeof module ? {
|
||||
module: {
|
||||
exports: {}
|
||||
}
|
||||
} : module)
|
||||
@@ -1,6 +1,9 @@
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="alert_window"></div>
|
||||
|
||||
<div id="footer" class="container" style="padding-top: 50px; display:none;">
|
||||
<footer class="footer">Copyright © 2013 <a target="_blank" href="http://www.nodebb.com">NodeBB</a> by <a target="_blank" href="https://github.com/psychobunny">psychobunny</a>, <a href="https://github.com/julianlam" target="_blank">julianlam</a>, <a href="https://github.com/barisusakli" target="_blank">barisusakli</a> from <a target="_blank" href="http://www.designcreateplay.com">designcreateplay</a></footer>
|
||||
</div>
|
||||
|
||||
@@ -63,8 +63,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="alert_window"></div>
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<a href="../../topic/{topics.slug}" id="tid-{topics.tid}">
|
||||
<li class="category-item {topics.deleted-class}">
|
||||
<div class="row">
|
||||
<div class="col-md-12 topic-row img-thumbnail">
|
||||
<div class="col-md-12 col-xs-12 topic-row img-thumbnail">
|
||||
<div class="latest-post visible-lg visible-md">
|
||||
<div class="pull-right">
|
||||
<img style="width: 48px; height: 48px; /*temporary*/" src="{topics.teaser_userpicture}" />
|
||||
|
||||
@@ -56,13 +56,8 @@
|
||||
</div>
|
||||
|
||||
<div id="content_{main_posts.pid}" class="post-content">{main_posts.content}</div>
|
||||
<div id="images_{main_posts.pid}" class="post-images">
|
||||
<!-- BEGIN uploadedImages -->
|
||||
<i class="icon-picture icon-1"></i><a href="{main_posts.uploadedImages.url}"> {main_posts.uploadedImages.name}</a><br/>
|
||||
<!-- END uploadedImages -->
|
||||
</div>
|
||||
<div class="post-signature">{main_posts.signature}</div>
|
||||
<div class="profile-block">
|
||||
<div class="post-info">
|
||||
<span class="pull-right">
|
||||
posted <span class="relativeTimeAgo">{main_posts.relativeTime} ago</span>
|
||||
<span class="{main_posts.edited-class}">| last edited by <strong><a href="/users/{main_posts.editorslug}">{main_posts.editorname}</a></strong> {main_posts.relativeEditTime} ago</span>
|
||||
@@ -116,13 +111,8 @@
|
||||
</div>
|
||||
|
||||
<div id="content_{posts.pid}" class="post-content">{posts.content}</div>
|
||||
<div id="images_{posts.pid}" class="post-images">
|
||||
<!-- BEGIN uploadedImages -->
|
||||
<i class="icon-picture icon-1"></i><a href="{posts.uploadedImages.url}"> {posts.uploadedImages.name}</a><br/>
|
||||
<!-- END uploadedImages -->
|
||||
</div>
|
||||
<div class="post-signature">{posts.signature}</div>
|
||||
<div class="profile-block">
|
||||
<div class="post-info">
|
||||
<span class="pull-right">
|
||||
posted <span class="relativeTimeAgo">{posts.relativeTime} ago</span>
|
||||
<span class="{posts.edited-class}">| last edited by <strong><a href="/users/{posts.editorslug}">{posts.editorname}</a></strong> {posts.relativeEditTime} ago</span>
|
||||
|
||||
@@ -35,15 +35,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
.profile-block {
|
||||
.main-post, .sub-posts {
|
||||
.post-info {
|
||||
background: rgba(0, 0, 0, 0.02);
|
||||
margin: 15px -11px -11px -11px;
|
||||
border-radius: 0 0 5px 5px;
|
||||
font-size: 10px;
|
||||
line-height: 15px;
|
||||
padding: 5px 8px 5px 5px;
|
||||
color: #777;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.active-users {
|
||||
color: rgb(153,153,153);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
.footer {
|
||||
display: none;
|
||||
text-align: center;
|
||||
|
||||
&.footer-stats {
|
||||
|
||||
@@ -42,10 +42,10 @@
|
||||
}
|
||||
|
||||
.main-post, .sub-posts {
|
||||
.profile-block, .post-block {
|
||||
.post-info, .post-block {
|
||||
position: relative;
|
||||
border: 1px solid rgba(0, 0, 0, 0.06);
|
||||
border-radius: 5px;
|
||||
border-radius: 0 0 5px 5px;
|
||||
padding: 10px;
|
||||
|
||||
.post-signature {
|
||||
@@ -64,6 +64,8 @@
|
||||
}
|
||||
|
||||
.post-block {
|
||||
border-radius: 5px;
|
||||
|
||||
.topic-buttons {
|
||||
background: rgba(0, 0, 0, 0.02);
|
||||
border: 1px solid rgba(0, 0, 0, 0.06);
|
||||
|
||||
@@ -106,4 +106,3 @@ var RDB = require('../redis'),
|
||||
};
|
||||
|
||||
}(exports));
|
||||
|
||||
|
||||
@@ -312,7 +312,9 @@ var RDB = require('./redis.js'),
|
||||
|
||||
Categories.getCategories = function(cids, callback, current_user) {
|
||||
if (!cids || !Array.isArray(cids) || cids.length === 0) {
|
||||
callback({'categories' : []});
|
||||
callback({
|
||||
'categories': []
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -342,7 +344,9 @@ var RDB = require('./redis.js'),
|
||||
return;
|
||||
}
|
||||
|
||||
callback({'categories': categories});
|
||||
callback({
|
||||
'categories': categories
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
@@ -32,7 +32,10 @@ var RDB = require('./redis.js'),
|
||||
}
|
||||
|
||||
if (room_id) {
|
||||
io.sockets.in(room_id).emit('event:rep_up', {uid: uid !== postData.uid ? postData.uid : 0, pid: pid});
|
||||
io.sockets. in (room_id).emit('event:rep_up', {
|
||||
uid: uid !== postData.uid ? postData.uid : 0,
|
||||
pid: pid
|
||||
});
|
||||
}
|
||||
|
||||
socket.emit('api:posts.favourite', {
|
||||
@@ -71,7 +74,10 @@ var RDB = require('./redis.js'),
|
||||
}
|
||||
|
||||
if (room_id) {
|
||||
io.sockets.in(room_id).emit('event:rep_down', {uid: uid !== uid_of_poster ? uid_of_poster : 0, pid: pid});
|
||||
io.sockets. in (room_id).emit('event:rep_down', {
|
||||
uid: uid !== uid_of_poster ? uid_of_poster : 0,
|
||||
pid: pid
|
||||
});
|
||||
}
|
||||
|
||||
socket.emit('api:posts.unfavourite', {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
var request = require('request');
|
||||
|
||||
|
||||
@@ -22,7 +20,10 @@ var request = require('request');
|
||||
}
|
||||
});
|
||||
|
||||
var upload = post.form({type:type, image:image});
|
||||
var upload = post.form({
|
||||
type: type,
|
||||
image: image
|
||||
});
|
||||
}
|
||||
|
||||
imgur.setClientID = function(id) {
|
||||
@@ -30,4 +31,3 @@ var request = require('request');
|
||||
}
|
||||
|
||||
}(exports));
|
||||
|
||||
|
||||
@@ -8,46 +8,38 @@ var async = require('async'),
|
||||
reds = require('reds'),
|
||||
|
||||
install = {
|
||||
questions: [
|
||||
{
|
||||
questions: [{
|
||||
name: 'base_url',
|
||||
description: 'URL of this installation',
|
||||
'default': 'http://localhost',
|
||||
pattern: /^http(?:s)?:\/\//,
|
||||
message: 'Base URL must begin with \'http://\' or \'https://\'',
|
||||
},
|
||||
{
|
||||
}, {
|
||||
name: 'port',
|
||||
description: 'Port number of your NodeBB',
|
||||
'default': 4567
|
||||
},
|
||||
{
|
||||
}, {
|
||||
name: 'use_port',
|
||||
description: 'Use a port number to access NodeBB?',
|
||||
'default': 'y',
|
||||
pattern: /y[es]*|n[o]?/,
|
||||
message: 'Please enter \'yes\' or \'no\'',
|
||||
},
|
||||
{
|
||||
}, {
|
||||
name: 'secret',
|
||||
description: 'Please enter a NodeBB secret',
|
||||
'default': utils.generateUUID()
|
||||
},
|
||||
{
|
||||
}, {
|
||||
name: 'redis:host',
|
||||
description: 'Host IP or address of your Redis instance',
|
||||
'default': '127.0.0.1'
|
||||
},
|
||||
{
|
||||
}, {
|
||||
name: 'redis:port',
|
||||
description: 'Host port of your Redis instance',
|
||||
'default': 6379
|
||||
},
|
||||
{
|
||||
}, {
|
||||
name: 'redis:password',
|
||||
description: 'Password of your Redis database'
|
||||
}
|
||||
],
|
||||
}],
|
||||
setup: function(callback) {
|
||||
async.series([
|
||||
function(next) {
|
||||
@@ -97,15 +89,28 @@ var async = require('async'),
|
||||
// Applying default database configs
|
||||
winston.info('Populating database with default configs, if not already set...')
|
||||
var meta = require('./meta'),
|
||||
defaults = [
|
||||
{ field: 'postDelay', value: 10000 },
|
||||
{ field: 'minimumPostLength', value: 8 },
|
||||
{ field: 'minimumTitleLength', value: 3 },
|
||||
{ field: 'minimumUsernameLength', value: 2 },
|
||||
{ field: 'maximumUsernameLength', value: 16 },
|
||||
{ field: 'minimumPasswordLength', value: 6 },
|
||||
{ field: 'imgurClientID', value: '' }
|
||||
];
|
||||
defaults = [{
|
||||
field: 'postDelay',
|
||||
value: 10000
|
||||
}, {
|
||||
field: 'minimumPostLength',
|
||||
value: 8
|
||||
}, {
|
||||
field: 'minimumTitleLength',
|
||||
value: 3
|
||||
}, {
|
||||
field: 'minimumUsernameLength',
|
||||
value: 2
|
||||
}, {
|
||||
field: 'maximumUsernameLength',
|
||||
value: 16
|
||||
}, {
|
||||
field: 'minimumPasswordLength',
|
||||
value: 6
|
||||
}, {
|
||||
field: 'imgurClientID',
|
||||
value: ''
|
||||
}];
|
||||
|
||||
async.each(defaults, function(configObj, next) {
|
||||
meta.configs.setOnEmpty(configObj.field, configObj.value, next);
|
||||
@@ -189,27 +194,23 @@ var async = require('async'),
|
||||
Groups = require('./groups');
|
||||
|
||||
winston.warn('No administrators have been detected, running initial user setup');
|
||||
var questions = [
|
||||
{
|
||||
var questions = [{
|
||||
name: 'username',
|
||||
description: 'Administrator username',
|
||||
required: true,
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
}, {
|
||||
name: 'email',
|
||||
description: 'Administrator email address',
|
||||
pattern: /.+@.+/,
|
||||
required: true
|
||||
},
|
||||
{
|
||||
}, {
|
||||
name: 'password',
|
||||
description: 'Password',
|
||||
required: true,
|
||||
hidden: true,
|
||||
type: 'string'
|
||||
}
|
||||
],
|
||||
}],
|
||||
getAdminInfo = function(callback) {
|
||||
prompt.get(questions, function(err, results) {
|
||||
if (!results) return callback(new Error('aborted'));
|
||||
@@ -251,7 +252,9 @@ var async = require('async'),
|
||||
], function(err) {
|
||||
winston.info('Configuration Saved OK');
|
||||
|
||||
nconf.file({ file: path.join(__dirname, '..', 'config.json') });
|
||||
nconf.file({
|
||||
file: path.join(__dirname, '..', 'config.json')
|
||||
});
|
||||
|
||||
var RDB = require('./redis');
|
||||
reds.createClient = function() {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
var user = require('./user.js'),
|
||||
bcrypt = require('bcrypt'),
|
||||
RDB = require('./redis.js'),
|
||||
@@ -41,7 +40,11 @@ var user = require('./user.js'),
|
||||
}
|
||||
|
||||
if (res) {
|
||||
next(null, { user: { uid: uid } });
|
||||
next(null, {
|
||||
user: {
|
||||
uid: uid
|
||||
}
|
||||
});
|
||||
} else {
|
||||
next(new Error('invalid-password'));
|
||||
}
|
||||
@@ -158,4 +161,3 @@ var user = require('./user.js'),
|
||||
}
|
||||
|
||||
}(exports));
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
var RDB = require('./redis'),
|
||||
async = require('async');
|
||||
|
||||
|
||||
@@ -130,4 +130,3 @@ var utils = require('./../public/src/utils.js'),
|
||||
|
||||
|
||||
}(exports));
|
||||
|
||||
|
||||
@@ -56,7 +56,8 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
|
||||
PostTools.edit = function(uid, pid, title, content, images) {
|
||||
|
||||
PostTools.edit = function(uid, pid, title, content) {
|
||||
var success = function() {
|
||||
posts.setPostField(pid, 'content', content);
|
||||
posts.setPostField(pid, 'edited', Date.now());
|
||||
@@ -67,11 +68,6 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
posts.uploadPostImages(pid, images, function(err, uploadedImages) {
|
||||
next(err, uploadedImages);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
posts.getPostField(pid, 'tid', function(tid) {
|
||||
PostTools.isMain(pid, tid, function(isMainPost) {
|
||||
@@ -82,7 +78,10 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
|
||||
next(null, {tid:tid, isMainPost:isMainPost});
|
||||
next(null, {
|
||||
tid: tid,
|
||||
isMainPost: isMainPost
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
@@ -90,12 +89,12 @@ var RDB = require('./redis.js'),
|
||||
PostTools.toHTML(content, next);
|
||||
}
|
||||
], function(err, results) {
|
||||
io.sockets.in('topic_' + results[1].tid).emit('event:post_edited', {
|
||||
io.sockets.in('topic_' + results[0].tid).emit('event:post_edited', {
|
||||
pid: pid,
|
||||
title: title,
|
||||
isMainPost: results[1].isMainPost,
|
||||
content: results[2],
|
||||
uploadedImages:results[0]
|
||||
isMainPost: results[0].isMainPost,
|
||||
content: results[1]
|
||||
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
76
src/posts.js
76
src/posts.js
@@ -124,8 +124,7 @@ var RDB = require('./redis.js'),
|
||||
plugins.fireHook('filter:post.get', data, function(data) {
|
||||
callback(data);
|
||||
});
|
||||
}
|
||||
else
|
||||
} else
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
@@ -134,8 +133,7 @@ var RDB = require('./redis.js'),
|
||||
RDB.hmgetObject('post:' + pid, fields, function(err, data) {
|
||||
if (err === null) {
|
||||
callback(data);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
@@ -166,17 +164,6 @@ var RDB = require('./redis.js'),
|
||||
postData['edited-class'] = postData.editor !== '' ? '' : 'none';
|
||||
postData['relativeEditTime'] = postData.edited !== '0' ? utils.relativeTime(postData.edited) : '';
|
||||
|
||||
if(postData.uploadedImages) {
|
||||
try {
|
||||
postData.uploadedImages = JSON.parse(postData.uploadedImages);
|
||||
} catch(err) {
|
||||
postData.uploadedImages = [];
|
||||
winston.err(err);
|
||||
}
|
||||
} else {
|
||||
postData.uploadedImages = [];
|
||||
}
|
||||
|
||||
postTools.toHTML(postData.content, function(err, content) {
|
||||
postData.content = content;
|
||||
posts.push(postData);
|
||||
@@ -226,7 +213,7 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
|
||||
Posts.reply = function(tid, uid, content, images, callback) {
|
||||
Posts.reply = function(tid, uid, content, callback) {
|
||||
if(content) {
|
||||
content = content.trim();
|
||||
}
|
||||
@@ -242,7 +229,7 @@ var RDB = require('./redis.js'),
|
||||
return;
|
||||
}
|
||||
|
||||
Posts.create(uid, tid, content, images, function(postData) {
|
||||
Posts.create(uid, tid, content, function(postData) {
|
||||
if (postData) {
|
||||
|
||||
topics.markUnRead(tid);
|
||||
@@ -256,7 +243,9 @@ var RDB = require('./redis.js'),
|
||||
threadTools.notify_followers(tid, uid);
|
||||
|
||||
Posts.addUserInfoToPost(postData, function() {
|
||||
var socketData = { posts: [postData] };
|
||||
var socketData = {
|
||||
posts: [postData]
|
||||
};
|
||||
io.sockets. in ('topic_' + tid).emit('event:new_post', socketData);
|
||||
io.sockets. in ('recent_posts').emit('event:new_post', socketData);
|
||||
io.sockets. in ('users/' + uid).emit('event:new_post', socketData);
|
||||
@@ -270,7 +259,7 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
};
|
||||
|
||||
Posts.create = function(uid, tid, content, images, callback) {
|
||||
Posts.create = function(uid, tid, content, callback) {
|
||||
if (uid === null) {
|
||||
callback(null);
|
||||
return;
|
||||
@@ -293,7 +282,6 @@ var RDB = require('./redis.js'),
|
||||
'editor': '',
|
||||
'edited': 0,
|
||||
'deleted': 0,
|
||||
'uploadedImages': '[]',
|
||||
'fav_button_class': '',
|
||||
'fav_star_class': 'icon-star-empty',
|
||||
'show_banned': 'hide',
|
||||
@@ -331,16 +319,6 @@ var RDB = require('./redis.js'),
|
||||
user.onNewPostMade(uid, tid, pid, timestamp);
|
||||
|
||||
async.parallel({
|
||||
uploadedImages: function(next) {
|
||||
Posts.uploadPostImages(postData.pid, images, function(err, uploadedImages) {
|
||||
if(err) {
|
||||
winston.error('Uploading images failed!', err.stack);
|
||||
next(null, []);
|
||||
} else {
|
||||
next(null, uploadedImages);
|
||||
}
|
||||
});
|
||||
},
|
||||
content: function(next) {
|
||||
plugins.fireHook('filter:post.get', postData, function(postData) {
|
||||
postTools.toHTML(postData.content, function(err, content) {
|
||||
@@ -349,7 +327,6 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
}, function(err, results) {
|
||||
postData.uploadedImages = results.uploadedImages;
|
||||
postData.content = results.content;
|
||||
callback(postData);
|
||||
});
|
||||
@@ -365,46 +342,29 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
|
||||
Posts.uploadPostImages = function(pid, images, callback) {
|
||||
Posts.uploadPostImage = function(image, callback) {
|
||||
var imgur = require('./imgur');
|
||||
imgur.setClientID(meta.config.imgurClientID);
|
||||
|
||||
if(!images)
|
||||
return callback(null, []);
|
||||
|
||||
var uploadedImages = images.filter(function(image) { return !!image.url; });
|
||||
|
||||
function uploadImage(image, next) {
|
||||
if(!image.data)
|
||||
return next(null);
|
||||
if(!image)
|
||||
return callback('invalid image', null);
|
||||
|
||||
imgur.upload(image.data, 'base64', function(err, data) {
|
||||
if(err) {
|
||||
next(err);
|
||||
callback('Can\'t upload image!', null);
|
||||
} else {
|
||||
if(data.success) {
|
||||
var img= {url:data.data.link, name:image.name};
|
||||
uploadedImages.push(img);
|
||||
next(null);
|
||||
|
||||
callback(null, img);
|
||||
} else {
|
||||
winston.error('Can\'t upload image, did you set imgurClientID?');
|
||||
next(data);
|
||||
callback("upload error", null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async.each(images, uploadImage, function(err) {
|
||||
if(!err) {
|
||||
Posts.setPostField(pid, 'uploadedImages', JSON.stringify(uploadedImages));
|
||||
callback(null, uploadedImages);
|
||||
} else {
|
||||
console.log(err);
|
||||
callback(err, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Posts.getPostsByUid = function(uid, start, end, callback) {
|
||||
|
||||
user.getPostIds(uid, start, end, function(pids) {
|
||||
@@ -414,8 +374,7 @@ var RDB = require('./redis.js'),
|
||||
Posts.getPostsByPids(pids, function(err, posts) {
|
||||
callback(posts);
|
||||
});
|
||||
}
|
||||
else
|
||||
} else
|
||||
callback([]);
|
||||
});
|
||||
}
|
||||
@@ -429,8 +388,7 @@ var RDB = require('./redis.js'),
|
||||
};
|
||||
|
||||
socket.emit('post.stats', stats);
|
||||
}
|
||||
else
|
||||
} else
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -45,8 +45,7 @@
|
||||
}
|
||||
|
||||
callback(null, returnData);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
console.log(err);
|
||||
callback(err, null);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
var user = require('./../user.js'),
|
||||
Groups = require('../groups'),
|
||||
topics = require('./../topics.js'),
|
||||
@@ -62,34 +61,59 @@ var user = require('./../user.js'),
|
||||
});
|
||||
|
||||
app.get('/api/admin/index', function(req, res) {
|
||||
res.json({version:pkg.version});
|
||||
res.json({
|
||||
version: pkg.version
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/admin/users/search', function(req, res) {
|
||||
res.json({search_display: 'block', loadmore_display:'none', users: []});
|
||||
res.json({
|
||||
search_display: 'block',
|
||||
loadmore_display: 'none',
|
||||
users: []
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/admin/users/latest', function(req, res) {
|
||||
user.getUsers('users:joindate', 0, 49, function(err, data) {
|
||||
res.json({ search_display: 'none', loadmore_display:'block', users:data, yourid:req.user.uid });
|
||||
res.json({
|
||||
search_display: 'none',
|
||||
loadmore_display: 'block',
|
||||
users: data,
|
||||
yourid: req.user.uid
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/admin/users/sort-posts', function(req, res) {
|
||||
user.getUsers('users:postcount', 0, 49, function(err, data) {
|
||||
res.json({ search_display: 'none', loadmore_display:'block', users:data, yourid:req.user.uid });
|
||||
res.json({
|
||||
search_display: 'none',
|
||||
loadmore_display: 'block',
|
||||
users: data,
|
||||
yourid: req.user.uid
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/admin/users/sort-reputation', function(req, res) {
|
||||
user.getUsers('users:reputation', 0, 49, function(err, data) {
|
||||
res.json({ search_display: 'none', loadmore_display:'block', users:data, yourid:req.user.uid });
|
||||
res.json({
|
||||
search_display: 'none',
|
||||
loadmore_display: 'block',
|
||||
users: data,
|
||||
yourid: req.user.uid
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/admin/users', function(req, res) {
|
||||
user.getUsers('users:joindate', 0, 49, function(err, data) {
|
||||
res.json({ search_display: 'none', users:data, yourid:req.user.uid });
|
||||
res.json({
|
||||
search_display: 'none',
|
||||
users: data,
|
||||
yourid: req.user.uid
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -246,7 +246,9 @@ var user = require('./../user.js'),
|
||||
});
|
||||
|
||||
app.get('/api/reset/:code', function(req, res) {
|
||||
res.json({ reset_code: req.params.code });
|
||||
res.json({
|
||||
reset_code: req.params.code
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/404', function(req, res) {
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
callbackURL: nconf.get('url') + 'auth/twitter/callback'
|
||||
}, function(token, tokenSecret, profile, done) {
|
||||
login_module.loginViaTwitter(profile.id, profile.username, profile.photos, function(err, user) {
|
||||
if (err) { return done(err); }
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
done(null, user);
|
||||
});
|
||||
}));
|
||||
@@ -40,7 +42,9 @@
|
||||
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) {
|
||||
if (err) { return done(err); }
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
done(null, user);
|
||||
});
|
||||
}));
|
||||
@@ -55,7 +59,9 @@
|
||||
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) {
|
||||
if (err) { return done(err); }
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
done(null, user);
|
||||
});
|
||||
}));
|
||||
@@ -90,7 +96,10 @@
|
||||
winston.info('[Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')');
|
||||
login_module.logout(req.sessionID, function(logout) {
|
||||
req.logout();
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + templates['logout'] + templates['footer']);
|
||||
});
|
||||
});
|
||||
@@ -107,7 +116,9 @@
|
||||
}
|
||||
|
||||
if (login_strategies.indexOf('google') !== -1) {
|
||||
app.get('/auth/google', passport.authenticate('google', { scope: 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email' }));
|
||||
app.get('/auth/google', passport.authenticate('google', {
|
||||
scope: 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'
|
||||
}));
|
||||
|
||||
app.get('/auth/google/callback', passport.authenticate('google', {
|
||||
successRedirect: '/',
|
||||
@@ -116,7 +127,9 @@
|
||||
}
|
||||
|
||||
if (login_strategies.indexOf('facebook') !== -1) {
|
||||
app.get('/auth/facebook', passport.authenticate('facebook', { scope: 'email' }));
|
||||
app.get('/auth/facebook', passport.authenticate('facebook', {
|
||||
scope: 'email'
|
||||
}));
|
||||
|
||||
app.get('/auth/facebook/callback', passport.authenticate('facebook', {
|
||||
successRedirect: '/',
|
||||
@@ -127,13 +140,19 @@
|
||||
|
||||
|
||||
app.get('/reset/:code', function(req, res) {
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route('reset/' + req.params.code) + templates['footer']);
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/reset', function(req, res) {
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route('reset') + templates['footer']);
|
||||
});
|
||||
});
|
||||
@@ -144,12 +163,18 @@
|
||||
return next(err);
|
||||
}
|
||||
if (!user) {
|
||||
return res.send({ success : false, message : info.message });
|
||||
return res.send({
|
||||
success: false,
|
||||
message: info.message
|
||||
});
|
||||
}
|
||||
req.login({
|
||||
uid: user.uid
|
||||
}, function() {
|
||||
res.send({ success : true, message : 'authentication succeeded' });
|
||||
res.send({
|
||||
success: true,
|
||||
message: 'authentication succeeded'
|
||||
});
|
||||
});
|
||||
})(req, res, next);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
(function(TestBed) {
|
||||
TestBed.create_routes = function(app) {
|
||||
|
||||
|
||||
@@ -18,38 +18,55 @@ var user = require('./../user.js'),
|
||||
if (data) {
|
||||
res.send(data);
|
||||
} else {
|
||||
res.json(404, {error:"User doesn't exist!"});
|
||||
res.json(404, {
|
||||
error: "User doesn't exist!"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
app.get('/users', function(req, res) {
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route("users", "users") + templates['footer']);
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/users-latest', function(req, res) {
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route("users-latest", "users") + templates['footer']);
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/users-sort-posts', function(req, res) {
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route("users-sort-posts", "users") + templates['footer']);
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/users-sort-reputation', function(req, res) {
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route("users-sort-reputation", "users") + templates['footer']);
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/users-search', function(req, res) {
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route("users-search", "users") + templates['footer']);
|
||||
});
|
||||
});
|
||||
@@ -66,7 +83,10 @@ var user = require('./../user.js'),
|
||||
return next();
|
||||
}
|
||||
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route('users/' + req.params.userslug, 'account') + templates['footer']);
|
||||
});
|
||||
|
||||
@@ -80,7 +100,10 @@ var user = require('./../user.js'),
|
||||
|
||||
user.getUserField(req.user.uid, 'userslug', function(err, userslug) {
|
||||
if (req.params.userslug && userslug === req.params.userslug) {
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route('users/' + req.params.userslug + '/edit', 'accountedit') + templates['footer']);
|
||||
});
|
||||
} else {
|
||||
@@ -96,7 +119,10 @@ var user = require('./../user.js'),
|
||||
|
||||
user.getUserField(req.user.uid, 'userslug', function(err, userslug) {
|
||||
if (req.params.userslug && userslug === req.params.userslug) {
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route('users/' + req.params.userslug + '/settings', 'accountsettings') + templates['footer']);
|
||||
})
|
||||
} else {
|
||||
@@ -177,7 +203,9 @@ var user = require('./../user.js'),
|
||||
winston.err(err);
|
||||
}
|
||||
|
||||
res.json({ path: imageUrl });
|
||||
res.json({
|
||||
path: imageUrl
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -200,7 +228,10 @@ var user = require('./../user.js'),
|
||||
return;
|
||||
}
|
||||
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route('users/' + req.params.userslug + '/following', 'following') + templates['footer']);
|
||||
});
|
||||
});
|
||||
@@ -216,7 +247,10 @@ var user = require('./../user.js'),
|
||||
res.redirect('/404');
|
||||
return;
|
||||
}
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route('users/' + req.params.userslug + '/followers', 'followers') + templates['footer']);
|
||||
});
|
||||
});
|
||||
@@ -232,7 +266,10 @@ var user = require('./../user.js'),
|
||||
res.redirect('/404');
|
||||
return;
|
||||
}
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route('users/' + req.params.userslug + '/favourites', 'favourites') + templates['footer']);
|
||||
});
|
||||
});
|
||||
@@ -250,7 +287,9 @@ var user = require('./../user.js'),
|
||||
});
|
||||
|
||||
} else {
|
||||
res.json(404, { error: 'User not found!' }) ;
|
||||
res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -266,7 +305,9 @@ var user = require('./../user.js'),
|
||||
res.json(userData);
|
||||
});
|
||||
} else {
|
||||
res.json(404, { error: 'User not found!' }) ;
|
||||
res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -284,12 +325,16 @@ var user = require('./../user.js'),
|
||||
|
||||
user.get_uid_by_userslug(req.params.userslug, function(err, uid) {
|
||||
if (!uid) {
|
||||
res.json(404, { error: 'User not found!' }) ;
|
||||
res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (uid !== callerUID || callerUID === "0") {
|
||||
res.json(403, { error: 'Not allowed!' });
|
||||
res.json(403, {
|
||||
error: 'Not allowed!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
user.getUserFields(uid, ['username', 'userslug', 'showemail'], function(err, userData) {
|
||||
@@ -303,7 +348,9 @@ var user = require('./../user.js'),
|
||||
userData.showemail = "";
|
||||
res.json(userData);
|
||||
} else {
|
||||
res.json(404, { error: 'User not found!' }) ;
|
||||
res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -314,12 +361,16 @@ var user = require('./../user.js'),
|
||||
|
||||
user.get_uid_by_userslug(req.params.userslug, function(err, uid) {
|
||||
if (!uid) {
|
||||
res.json(404, { error: 'User not found!' }) ;
|
||||
res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (uid !== callerUID || callerUID === "0") {
|
||||
res.json(403, { error: 'Not allowed!' });
|
||||
res.json(403, {
|
||||
error: 'Not allowed!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -336,7 +387,9 @@ var user = require('./../user.js'),
|
||||
res.json(userData);
|
||||
});
|
||||
} else {
|
||||
res.json(404, { error: 'User not found!' }) ;
|
||||
res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -350,7 +403,9 @@ var user = require('./../user.js'),
|
||||
user.isFollowing(callerUID, userData.theirid, function(isFollowing) {
|
||||
posts.getPostsByUid(userData.theirid, 0, 9, function(posts) {
|
||||
|
||||
userData.posts = posts.filter(function(p) {return p.deleted !== "1";});
|
||||
userData.posts = posts.filter(function(p) {
|
||||
return p.deleted !== "1";
|
||||
});
|
||||
userData.isFollowing = isFollowing;
|
||||
if (!userData.profileviews)
|
||||
userData.profileviews = 1;
|
||||
@@ -364,7 +419,9 @@ var user = require('./../user.js'),
|
||||
});
|
||||
});
|
||||
} else {
|
||||
res.json(404, { error: 'User not found!' }) ;
|
||||
res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -378,24 +435,40 @@ var user = require('./../user.js'),
|
||||
|
||||
function getUsersSortedByJoinDate(req, res) {
|
||||
user.getUsers('users:joindate', 0, 49, function(err, data) {
|
||||
res.json({ search_display: 'none', loadmore_display:'block', users:data });
|
||||
res.json({
|
||||
search_display: 'none',
|
||||
loadmore_display: 'block',
|
||||
users: data
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getUsersSortedByPosts(req, res) {
|
||||
user.getUsers('users:postcount', 0, 49, function(err, data) {
|
||||
res.json({ search_display: 'none', loadmore_display:'block', users:data });
|
||||
res.json({
|
||||
search_display: 'none',
|
||||
loadmore_display: 'block',
|
||||
users: data
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getUsersSortedByReputation(req, res) {
|
||||
user.getUsers('users:reputation', 0, 49, function(err, data) {
|
||||
res.json({ search_display: 'none', loadmore_display:'block', users:data });
|
||||
res.json({
|
||||
search_display: 'none',
|
||||
loadmore_display: 'block',
|
||||
users: data
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getUsersForSearch(req, res) {
|
||||
res.json({ search_display: 'block', loadmore_display:'none', users: [] });
|
||||
res.json({
|
||||
search_display: 'block',
|
||||
loadmore_display: 'none',
|
||||
users: []
|
||||
});
|
||||
}
|
||||
|
||||
function getUserDataByUserSlug(userslug, callerUID, callback) {
|
||||
|
||||
@@ -6,11 +6,19 @@ var path = require('path'),
|
||||
topics = require('./topics'),
|
||||
sitemap = {
|
||||
getStaticUrls: function(callback) {
|
||||
callback(null, [
|
||||
{ url: '', changefreq: 'weekly', priority: '0.6' },
|
||||
{ url: 'recent', changefreq: 'daily', priority: '0.4' },
|
||||
{ url: 'users', changefreq: 'daily', priority: '0.4' }
|
||||
]);
|
||||
callback(null, [{
|
||||
url: '',
|
||||
changefreq: 'weekly',
|
||||
priority: '0.6'
|
||||
}, {
|
||||
url: 'recent',
|
||||
changefreq: 'daily',
|
||||
priority: '0.4'
|
||||
}, {
|
||||
url: 'users',
|
||||
changefreq: 'daily',
|
||||
priority: '0.4'
|
||||
}]);
|
||||
},
|
||||
getDynamicUrls: function(callback) {
|
||||
var returnUrls = [];
|
||||
|
||||
@@ -240,7 +240,9 @@ var RDB = require('./redis.js'),
|
||||
status: 'ok',
|
||||
follow: true
|
||||
});
|
||||
} else callback({ status: 'error' });
|
||||
} else callback({
|
||||
status: 'error'
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -251,7 +253,9 @@ var RDB = require('./redis.js'),
|
||||
status: 'ok',
|
||||
follow: false
|
||||
});
|
||||
} else callback({ status: 'error' });
|
||||
} else callback({
|
||||
status: 'error'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -129,7 +129,9 @@ var RDB = require('./redis.js')
|
||||
done = false;
|
||||
|
||||
async.whilst(
|
||||
function () { return unreadTids.length < 21 && !done; },
|
||||
function() {
|
||||
return unreadTids.length < 21 && !done;
|
||||
},
|
||||
function(callback) {
|
||||
RDB.zrevrange('topics:recent', start, stop, function(err, tids) {
|
||||
|
||||
@@ -197,7 +199,9 @@ var RDB = require('./redis.js')
|
||||
done = false;
|
||||
|
||||
async.whilst(
|
||||
function () { return unreadTids.length < 20 && !done; },
|
||||
function() {
|
||||
return unreadTids.length < 20 && !done;
|
||||
},
|
||||
function(callback) {
|
||||
RDB.zrevrange('topics:recent', start, stop, function(err, tids) {
|
||||
if (err)
|
||||
@@ -266,6 +270,7 @@ var RDB = require('./redis.js')
|
||||
}
|
||||
|
||||
// temporary. I don't think this call should belong here
|
||||
|
||||
function getPrivileges(next) {
|
||||
categories.privileges(category_id, current_user, function(user_privs) {
|
||||
next(null, user_privs);
|
||||
@@ -438,7 +443,9 @@ var RDB = require('./redis.js')
|
||||
numTids, x;
|
||||
|
||||
// Sort into ascending order
|
||||
tids.sort(function(a, b) { return a - b; });
|
||||
tids.sort(function(a, b) {
|
||||
return a - b;
|
||||
});
|
||||
|
||||
// Eliminate everything after the "after" tid
|
||||
if (after) {
|
||||
@@ -457,7 +464,9 @@ var RDB = require('./redis.js')
|
||||
}
|
||||
|
||||
// Sort into descending order
|
||||
tids.sort(function(a, b) { return b - a; });
|
||||
tids.sort(function(a, b) {
|
||||
return b - a;
|
||||
});
|
||||
|
||||
async.each(tids, function(tid, next) {
|
||||
Topics.getTopicDataWithUsername(tid, function(topicData) {
|
||||
@@ -604,7 +613,7 @@ var RDB = require('./redis.js')
|
||||
});
|
||||
}
|
||||
|
||||
Topics.post = function(uid, title, content, category_id, images, callback) {
|
||||
Topics.post = function(uid, title, content, category_id, callback) {
|
||||
if (!category_id)
|
||||
throw new Error('Attempted to post without a category_id');
|
||||
|
||||
@@ -678,7 +687,7 @@ var RDB = require('./redis.js')
|
||||
|
||||
feed.updateCategory(category_id);
|
||||
|
||||
posts.create(uid, tid, content, images, function(postData) {
|
||||
posts.create(uid, tid, content, function(postData) {
|
||||
if (postData) {
|
||||
|
||||
// Auto-subscribe the post creator to the newly created topic
|
||||
@@ -688,7 +697,9 @@ var RDB = require('./redis.js')
|
||||
Topics.getTopicForCategoryView(tid, uid, function(topicData) {
|
||||
io.sockets. in ('category_' + category_id).emit('event:new_topic', topicData);
|
||||
io.sockets. in ('recent_posts').emit('event:new_topic', topicData);
|
||||
io.sockets.in('users/' + uid).emit('event:new_post', {posts:postData});
|
||||
io.sockets. in ('users/' + uid).emit('event:new_post', {
|
||||
posts: postData
|
||||
});
|
||||
});
|
||||
|
||||
callback(null, postData);
|
||||
|
||||
@@ -24,8 +24,7 @@ function upgradeCategory(cid, callback) {
|
||||
if (!err) {
|
||||
RDB.rename('temp_categories:' + cid + ':tid', 'categories:' + cid + ':tid');
|
||||
callback(null);
|
||||
}
|
||||
else
|
||||
} else
|
||||
callback(err);
|
||||
});
|
||||
|
||||
|
||||
94
src/user.js
94
src/user.js
@@ -87,7 +87,9 @@ var utils = require('./../public/src/utils.js'),
|
||||
RDB.incr('usercount', function(err, count) {
|
||||
RDB.handle(err);
|
||||
|
||||
if (typeof io !== 'undefined') io.sockets.emit('user.count', {count: count});
|
||||
if (typeof io !== 'undefined') io.sockets.emit('user.count', {
|
||||
count: count
|
||||
});
|
||||
});
|
||||
|
||||
RDB.zadd('users:joindate', timestamp, uid);
|
||||
@@ -96,7 +98,10 @@ var utils = require('./../public/src/utils.js'),
|
||||
|
||||
userSearch.index(username, uid);
|
||||
|
||||
if (typeof io !== 'undefined') io.sockets.emit('user.latest', {userslug: userslug, username: username});
|
||||
if (typeof io !== 'undefined') io.sockets.emit('user.latest', {
|
||||
userslug: userslug,
|
||||
username: username
|
||||
});
|
||||
|
||||
if (password !== undefined) {
|
||||
User.hashPassword(password, function(err, hash) {
|
||||
@@ -195,11 +200,15 @@ var utils = require('./../public/src/utils.js'),
|
||||
User.updateProfile = function(uid, data, callback) {
|
||||
|
||||
var fields = ['email', 'fullname', 'website', 'location', 'birthday', 'signature'];
|
||||
var returnData = {success:false};
|
||||
var returnData = {
|
||||
success: false
|
||||
};
|
||||
|
||||
function isSignatureValid(next) {
|
||||
if (data['signature'] !== undefined && data['signature'].length > 150) {
|
||||
next({error:'Signature can\'t be longer than 150 characters!'}, false);
|
||||
next({
|
||||
error: 'Signature can\'t be longer than 150 characters!'
|
||||
}, false);
|
||||
} else {
|
||||
next(null, true);
|
||||
}
|
||||
@@ -216,7 +225,9 @@ var utils = require('./../public/src/utils.js'),
|
||||
if (err)
|
||||
return next(err, null);
|
||||
if (!available) {
|
||||
next({error:'Email not available!'}, false);
|
||||
next({
|
||||
error: 'Email not available!'
|
||||
}, false);
|
||||
} else {
|
||||
next(null, true);
|
||||
}
|
||||
@@ -283,7 +294,9 @@ var utils = require('./../public/src/utils.js'),
|
||||
|
||||
User.changePassword = function(uid, data, callback) {
|
||||
if (!utils.isPasswordValid(data.newPassword)) {
|
||||
return callback({error:'Invalid password!'});
|
||||
return callback({
|
||||
error: 'Invalid password!'
|
||||
});
|
||||
}
|
||||
|
||||
User.getUserField(uid, 'password', function(err, user_password) {
|
||||
@@ -299,7 +312,9 @@ var utils = require('./../public/src/utils.js'),
|
||||
callback(null);
|
||||
});
|
||||
} else {
|
||||
callback({error:'Your current password is not correct!'});
|
||||
callback({
|
||||
error: 'Your current password is not correct!'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -448,8 +463,12 @@ var utils = require('./../public/src/utils.js'),
|
||||
if (meta.config['email:host'] && meta.config['email:port'] && meta.config['email:from']) {
|
||||
var confirm_code = utils.generateUUID(),
|
||||
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 });
|
||||
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
|
||||
});
|
||||
|
||||
// Email confirmation code
|
||||
var expiry_time = 60 * 60 * 2, // Expire after 2 hours
|
||||
@@ -467,12 +486,10 @@ var utils = require('./../public/src/utils.js'),
|
||||
from: meta.config.mailer.from,
|
||||
to: email,
|
||||
subject: '[NodeBB] Registration Email Verification',
|
||||
attachment: [
|
||||
{
|
||||
attachment: [{
|
||||
data: confirm_email,
|
||||
alternative: true
|
||||
}
|
||||
]
|
||||
}]
|
||||
});
|
||||
|
||||
emailjsServer.send(message, function(err, success) {
|
||||
@@ -612,7 +629,9 @@ var utils = require('./../public/src/utils.js'),
|
||||
RDB.get('usercount', function(err, count) {
|
||||
RDB.handle(err);
|
||||
|
||||
socket.emit('user.count', { count: count ? count : 0 });
|
||||
socket.emit('user.count', {
|
||||
count: count ? count : 0
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -622,7 +641,10 @@ var utils = require('./../public/src/utils.js'),
|
||||
|
||||
User.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
|
||||
if (!err && userData)
|
||||
socket.emit('user.latest', {userslug: userData.userslug, username: userData.username});
|
||||
socket.emit('user.latest', {
|
||||
userslug: userData.userslug,
|
||||
username: userData.username
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -771,7 +793,9 @@ var utils = require('./../public/src/utils.js'),
|
||||
|
||||
if (expiry >= +Date.now() / 1000 | 0) {
|
||||
if (!callback) {
|
||||
socket.emit('user:reset.valid', { valid: true });
|
||||
socket.emit('user:reset.valid', {
|
||||
valid: true
|
||||
});
|
||||
} else {
|
||||
callback(true);
|
||||
}
|
||||
@@ -780,7 +804,9 @@ var utils = require('./../public/src/utils.js'),
|
||||
RDB.del('reset:' + code + ':uid');
|
||||
RDB.del('reset:' + code + ':expiry');
|
||||
if (!callback) {
|
||||
socket.emit('user:reset.valid', { valid: false });
|
||||
socket.emit('user:reset.valid', {
|
||||
valid: false
|
||||
});
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
@@ -788,7 +814,9 @@ var utils = require('./../public/src/utils.js'),
|
||||
});
|
||||
} else {
|
||||
if (!callback) {
|
||||
socket.emit('user:reset.valid', { valid: false });
|
||||
socket.emit('user:reset.valid', {
|
||||
valid: false
|
||||
});
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
@@ -804,20 +832,22 @@ var utils = require('./../public/src/utils.js'),
|
||||
RDB.set('reset:' + reset_code + ':expiry', (60 * 60) + new Date() / 1000 | 0); // Active for one hour
|
||||
|
||||
var reset_link = nconf.get('url') + 'reset/' + reset_code,
|
||||
reset_email = global.templates['emails/reset'].parse({'RESET_LINK': reset_link}),
|
||||
reset_email_plaintext = global.templates['emails/reset_plaintext'].parse({ 'RESET_LINK': reset_link });
|
||||
reset_email = global.templates['emails/reset'].parse({
|
||||
'RESET_LINK': reset_link
|
||||
}),
|
||||
reset_email_plaintext = global.templates['emails/reset_plaintext'].parse({
|
||||
'RESET_LINK': reset_link
|
||||
});
|
||||
|
||||
var message = emailjs.message.create({
|
||||
text: reset_email_plaintext,
|
||||
from: meta.config.mailer ? meta.config.mailer.from : 'localhost@example.org',
|
||||
to: email,
|
||||
subject: 'Password Reset Requested',
|
||||
attachment: [
|
||||
{
|
||||
attachment: [{
|
||||
data: reset_email,
|
||||
alternative: true
|
||||
}
|
||||
]
|
||||
}]
|
||||
});
|
||||
|
||||
emailjsServer.send(message, function(err, success) {
|
||||
@@ -860,7 +890,9 @@ var utils = require('./../public/src/utils.js'),
|
||||
RDB.del('reset:' + code + ':uid');
|
||||
RDB.del('reset:' + code + ':expiry');
|
||||
|
||||
socket.emit('user:reset.commit', { status: 'ok' });
|
||||
socket.emit('user:reset.commit', {
|
||||
status: 'ok'
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -872,7 +904,9 @@ var utils = require('./../public/src/utils.js'),
|
||||
User.get_uid_by_email(email, function(exists) {
|
||||
exists = !! exists;
|
||||
if (typeof callback !== 'function') {
|
||||
socket.emit('user.email.exists', { exists: exists });
|
||||
socket.emit('user.email.exists', {
|
||||
exists: exists
|
||||
});
|
||||
} else {
|
||||
callback(exists);
|
||||
}
|
||||
@@ -887,9 +921,13 @@ var utils = require('./../public/src/utils.js'),
|
||||
if (email !== null) {
|
||||
RDB.set('email:' + email + ':confirm', true);
|
||||
RDB.del('confirm:' + code + ':email');
|
||||
callback({ status: 'ok' });
|
||||
callback({
|
||||
status: 'ok'
|
||||
});
|
||||
} else {
|
||||
callback({ status: 'not_ok' });
|
||||
callback({
|
||||
status: 'not_ok'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
126
src/webserver.js
126
src/webserver.js
@@ -31,12 +31,19 @@ var express = require('express'),
|
||||
* accepts: metaTags
|
||||
*/
|
||||
app.build_header = function(options, callback) {
|
||||
var defaultMetaTags = [
|
||||
{ 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: meta.config.title || 'NodeBB' },
|
||||
],
|
||||
var defaultMetaTags = [{
|
||||
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: meta.config.title || 'NodeBB'
|
||||
}, ],
|
||||
metaString = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || [])),
|
||||
templateValues = {
|
||||
cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
|
||||
@@ -58,7 +65,10 @@ var express = require('express'),
|
||||
|
||||
// Middlewares
|
||||
app.use(express.favicon(path.join(__dirname, '../', 'public', 'favicon.ico')));
|
||||
app.use(require('less-middleware')({ src: path.join(__dirname, '../', 'public'), prefix:nconf.get('relative_path') }));
|
||||
app.use(require('less-middleware')({
|
||||
src: path.join(__dirname, '../', 'public'),
|
||||
prefix: nconf.get('relative_path')
|
||||
}));
|
||||
app.use(nconf.get('relative_path'), express.static(path.join(__dirname, '../', 'public')));
|
||||
app.use(express.bodyParser()); // Puts POST vars in request.body
|
||||
|
||||
@@ -138,7 +148,9 @@ var express = require('express'),
|
||||
|
||||
// respond with json
|
||||
if (req.accepts('json')) {
|
||||
res.send({ error: 'Not found' });
|
||||
res.send({
|
||||
error: 'Not found'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -155,7 +167,9 @@ var express = require('express'),
|
||||
|
||||
res.status(err.status || 500);
|
||||
|
||||
res.json('500', { error: err.message });
|
||||
res.json('500', {
|
||||
error: err.message
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -189,7 +203,10 @@ var express = require('express'),
|
||||
return;
|
||||
}
|
||||
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route(route) + templates['footer']);
|
||||
});
|
||||
});
|
||||
@@ -204,12 +221,19 @@ var express = require('express'),
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res,
|
||||
metaTags: [
|
||||
{ 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' }
|
||||
]
|
||||
metaTags: [{
|
||||
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);
|
||||
},
|
||||
"categories": function(next) {
|
||||
@@ -275,16 +299,31 @@ var express = require('express'),
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res,
|
||||
metaTags: [
|
||||
{ name: "title", content: topicData.topic_name },
|
||||
{ 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 },
|
||||
{ property: "article:published_time", content: new Date(parseInt(topicData.main_posts[0].timestamp, 10)).toISOString() },
|
||||
{ property: 'article:modified_time', content: new Date(lastMod).toISOString() },
|
||||
{ property: 'article:section', content: topicData.category_name }
|
||||
]
|
||||
metaTags: [{
|
||||
name: "title",
|
||||
content: topicData.topic_name
|
||||
}, {
|
||||
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
|
||||
}, {
|
||||
property: "article:published_time",
|
||||
content: new Date(parseInt(topicData.main_posts[0].timestamp, 10)).toISOString()
|
||||
}, {
|
||||
property: 'article:modified_time',
|
||||
content: new Date(lastMod).toISOString()
|
||||
}, {
|
||||
property: 'article:section',
|
||||
content: topicData.category_name
|
||||
}]
|
||||
}, function(err, header) {
|
||||
next(err, {
|
||||
header: header,
|
||||
@@ -344,11 +383,16 @@ var express = require('express'),
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res,
|
||||
metaTags: [
|
||||
{ name: 'title', content: categoryData.category_name },
|
||||
{ name: 'description', content: categoryData.category_description },
|
||||
{ property: "og:type", content: 'website' }
|
||||
]
|
||||
metaTags: [{
|
||||
name: 'title',
|
||||
content: categoryData.category_name
|
||||
}, {
|
||||
name: 'description',
|
||||
content: categoryData.category_description
|
||||
}, {
|
||||
property: "og:type",
|
||||
content: 'website'
|
||||
}]
|
||||
}, function(err, header) {
|
||||
next(err, {
|
||||
header: header,
|
||||
@@ -370,7 +414,10 @@ var express = require('express'),
|
||||
});
|
||||
|
||||
app.get('/confirm/:code', function(req, res) {
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + '<script>templates.ready(function(){ajaxify.go("confirm/' + req.params.code + '");});</script>' + templates['footer']);
|
||||
});
|
||||
});
|
||||
@@ -421,7 +468,10 @@ var express = require('express'),
|
||||
app.get('/outgoing', function(req, res) {
|
||||
if (!req.query.url) return res.redirect('/404');
|
||||
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(
|
||||
header +
|
||||
'\n\t<script>templates.ready(function(){ajaxify.go("outgoing?url=' + encodeURIComponent(req.query.url) + '", null, null, true);});</script>' +
|
||||
@@ -431,13 +481,19 @@ var express = require('express'),
|
||||
});
|
||||
|
||||
app.get('/search', function(req, res) {
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route("search", null, "search") + templates['footer']);
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/search/:term', function(req, res) {
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res
|
||||
}, function(err, header) {
|
||||
res.send(header + app.create_route("search/" + req.params.term, null, "search") + templates['footer']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
var SocketIO = require('socket.io').listen(global.server, {
|
||||
log: false,
|
||||
transports: ['websocket', 'xhr-polling', 'jsonp-polling', 'flashsocket']
|
||||
@@ -58,7 +57,11 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
io.sockets. in ('global').emit('api:user.isOnline', isUserOnline(uid));
|
||||
|
||||
user.getUserField(uid, 'username', function(err, username) {
|
||||
socket.emit('event:connect', {status: 1, username:username, uid:uid});
|
||||
socket.emit('event:connect', {
|
||||
status: 1,
|
||||
username: username,
|
||||
uid: uid
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -191,13 +194,14 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
socket.emit('api:updateHeader', fields);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
socket.emit('api:updateHeader', {
|
||||
uid: 0,
|
||||
username: "Anonymous User",
|
||||
email: '',
|
||||
picture: require('gravatar').url('', {s:'24'}, https=nconf.get('https'))
|
||||
picture: require('gravatar').url('', {
|
||||
s: '24'
|
||||
}, https = nconf.get('https'))
|
||||
});
|
||||
}
|
||||
|
||||
@@ -206,7 +210,9 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
socket.on('user.exists', function(data) {
|
||||
if (data.username) {
|
||||
user.exists(utils.slugify(data.username), function(exists) {
|
||||
socket.emit('user.exists', {exists: exists});
|
||||
socket.emit('user.exists', {
|
||||
exists: exists
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -257,7 +263,10 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
});
|
||||
|
||||
socket.on('api:user.isOnline', function(uid, callback) {
|
||||
callback({online:isUserOnline(uid), timestamp:Date.now()});
|
||||
callback({
|
||||
online: isUserOnline(uid),
|
||||
timestamp: Date.now()
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('api:user.changePassword', function(data, callback) {
|
||||
@@ -322,7 +331,7 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
|
||||
socket.on('api:topics.post', function(data) {
|
||||
|
||||
topics.post(uid, data.title, data.content, data.category_id, data.images, function(err, result) {
|
||||
topics.post(uid, data.title, data.content, data.category_id, function(err, result) {
|
||||
if(err) {
|
||||
if(err.message === 'not-logged-in') {
|
||||
socket.emit('event:alert', {
|
||||
@@ -379,7 +388,7 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
return;
|
||||
}
|
||||
|
||||
posts.reply(data.topic_id, uid, data.content, data.images, function(err, result) {
|
||||
posts.reply(data.topic_id, uid, data.content, function(err, result) {
|
||||
if(err) {
|
||||
if(err.message === 'content-too-short') {
|
||||
posts.emitContentTooShortAlert(socket);
|
||||
@@ -477,9 +486,15 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('api:posts.uploadImage', function(data, callback) {
|
||||
posts.uploadPostImage(data, callback);
|
||||
});
|
||||
|
||||
socket.on('api:posts.getRawPost', function(data) {
|
||||
posts.getPostField(data.pid, 'content', function(raw) {
|
||||
socket.emit('api:posts.getRawPost', { post: raw });
|
||||
socket.emit('api:posts.getRawPost', {
|
||||
post: raw
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -562,7 +577,12 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
numSockets = userSockets[touid].length;
|
||||
|
||||
for (var x = 0; x < numSockets; ++x) {
|
||||
userSockets[touid][x].emit('chatMessage', {fromuid:uid, username:username, message: finalMessage, timestamp: Date.now()});
|
||||
userSockets[touid][x].emit('chatMessage', {
|
||||
fromuid: uid,
|
||||
username: username,
|
||||
message: finalMessage,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -571,7 +591,12 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
numSockets = userSockets[uid].length;
|
||||
|
||||
for (var x = 0; x < numSockets; ++x) {
|
||||
userSockets[uid][x].emit('chatMessage', {fromuid:touid, username:username, message:'You : ' + msg, timestamp: Date.now()});
|
||||
userSockets[uid][x].emit('chatMessage', {
|
||||
fromuid: touid,
|
||||
username: username,
|
||||
message: 'You : ' + msg,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -586,7 +611,9 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
|
||||
socket.on('api:config.set', function(data) {
|
||||
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'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -623,14 +650,7 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
posts.getPostFields(data.pid, ['content', 'uploadedImages'], function(raw) {
|
||||
try {
|
||||
raw.uploadedImages = JSON.parse(raw.uploadedImages);
|
||||
} catch(e) {
|
||||
winston.err(e);
|
||||
raw.uploadedImages = [];
|
||||
}
|
||||
|
||||
posts.getPostFields(data.pid, ['content'], function(raw) {
|
||||
next(null, raw);
|
||||
});
|
||||
},
|
||||
@@ -643,8 +663,7 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
socket.emit('api:composer.push', {
|
||||
title: results[1],
|
||||
pid: data.pid,
|
||||
body: results[0].content,
|
||||
uploadedImages: results[0].uploadedImages
|
||||
body: results[0].content
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -696,7 +715,9 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
end = start + 9;
|
||||
|
||||
topics.getTopicPosts(data.tid, start, end, uid, function(posts) {
|
||||
callback({posts:posts});
|
||||
callback({
|
||||
posts: posts
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -705,7 +726,9 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
end = start + 9;
|
||||
|
||||
categories.getCategoryTopics(data.cid, start, end, uid, function(topics) {
|
||||
callback({topics:topics});
|
||||
callback({
|
||||
topics: topics
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -735,7 +758,9 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
if (err) {
|
||||
winston.err(err);
|
||||
} else {
|
||||
callback({users:data});
|
||||
callback({
|
||||
users: data
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user