mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-31 19:15:58 +01:00
fixing social network logins and refactoring post actions
This commit is contained in:
133
src/posts.js
133
src/posts.js
@@ -27,7 +27,6 @@ marked.setOptions({
|
|||||||
//compile thread after all data is asynchronously called
|
//compile thread after all data is asynchronously called
|
||||||
function generateThread() {
|
function generateThread() {
|
||||||
if (!post_data || !user_data || !thread_data || !vote_data || !viewer_data) return;
|
if (!post_data || !user_data || !thread_data || !vote_data || !viewer_data) return;
|
||||||
console.log(viewer_data);
|
|
||||||
|
|
||||||
var posts = [],
|
var posts = [],
|
||||||
main_posts = [],
|
main_posts = [],
|
||||||
@@ -38,7 +37,8 @@ marked.setOptions({
|
|||||||
var uid = post_data.uid[i],
|
var uid = post_data.uid[i],
|
||||||
pid = post_data.pid[i];
|
pid = post_data.pid[i];
|
||||||
|
|
||||||
if (post_data.deleted[i] === null || (post_data.deleted[i] === '1' && manage_content)) {
|
console.log(current_user, uid);
|
||||||
|
if (post_data.deleted[i] === null || (post_data.deleted[i] === '1' && manage_content) || current_user === uid) {
|
||||||
var post_obj = {
|
var post_obj = {
|
||||||
'pid' : pid,
|
'pid' : pid,
|
||||||
'uid' : uid,
|
'uid' : uid,
|
||||||
@@ -181,8 +181,31 @@ marked.setOptions({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Posts.editable = function(uid, pid) {
|
Posts.editable = function(uid, pid, callback) {
|
||||||
|
async.parallel([
|
||||||
|
function(next) {
|
||||||
|
RDB.get('pid:' + pid + ':uid', function(err, author) {
|
||||||
|
if (author && parseInt(author) > 0) next(null, author === uid);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
user.getUserField(uid, 'reputation', function(reputation) {
|
||||||
|
next(null, reputation >= config.privilege_thresholds.manage_content);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
Posts.get_tid_by_pid(pid, function(tid) {
|
||||||
|
RDB.get('tid:' + tid + ':cid', function(err, cid) {
|
||||||
|
user.isModerator(uid, cid, function(isMod) {
|
||||||
|
next(null, isMod);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
], function(err, results) {
|
||||||
|
// If any return true, allow the edit
|
||||||
|
if (results.indexOf(true) !== -1) callback(true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Posts.get_tid_by_pid = function(pid, callback) {
|
Posts.get_tid_by_pid = function(pid, callback) {
|
||||||
@@ -419,118 +442,46 @@ marked.setOptions({
|
|||||||
}
|
}
|
||||||
|
|
||||||
Posts.edit = function(uid, pid, content) {
|
Posts.edit = function(uid, pid, content) {
|
||||||
RDB.mget(['pid:' + pid + ':tid', 'pid:' + pid + ':uid'], function(err, results) {
|
var success = function() {
|
||||||
var tid = results[0],
|
|
||||||
author = results[1],
|
|
||||||
success = function() {
|
|
||||||
RDB.set('pid:' + pid + ':content', content);
|
RDB.set('pid:' + pid + ':content', content);
|
||||||
RDB.set('pid:' + pid + ':edited', new Date().getTime());
|
RDB.set('pid:' + pid + ':edited', new Date().getTime());
|
||||||
RDB.set('pid:' + pid + ':editor', uid);
|
RDB.set('pid:' + pid + ':editor', uid);
|
||||||
|
|
||||||
|
Posts.get_tid_by_pid(pid, function(tid) {
|
||||||
io.sockets.in('topic_' + tid).emit('event:post_edited', { pid: pid, content: marked(content || '') });
|
io.sockets.in('topic_' + tid).emit('event:post_edited', { pid: pid, content: marked(content || '') });
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (uid === author) success();
|
Posts.editable(uid, pid, function(editable) {
|
||||||
else {
|
if (editable) success();
|
||||||
async.parallel([
|
|
||||||
function(callback) {
|
|
||||||
user.getUserField(uid, 'reputation', function(reputation) {
|
|
||||||
callback(null, reputation >= config.privilege_thresholds.manage_content);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function(callback) {
|
|
||||||
RDB.get('tid:' + tid + ':cid', function(err, cid) {
|
|
||||||
user.isModerator(uid, cid, function(isMod) {
|
|
||||||
callback(null, isMod);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
], function(err, results) {
|
|
||||||
// If any return true, allow the edit
|
|
||||||
for(var x=0,numResults=results.length;x<numResults;x++) {
|
|
||||||
if (results[x]) {
|
|
||||||
success();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Posts.delete = function(uid, pid) {
|
Posts.delete = function(uid, pid) {
|
||||||
RDB.mget(['pid:' + pid + ':tid', 'pid:' + pid + ':uid'], function(err, results) {
|
var success = function() {
|
||||||
var tid = results[0],
|
|
||||||
author = results[1],
|
|
||||||
success = function() {
|
|
||||||
RDB.set('pid:' + pid + ':deleted', 1);
|
RDB.set('pid:' + pid + ':deleted', 1);
|
||||||
|
|
||||||
|
Posts.get_tid_by_pid(pid, function(tid) {
|
||||||
io.sockets.in('topic_' + tid).emit('event:post_deleted', { pid: pid });
|
io.sockets.in('topic_' + tid).emit('event:post_deleted', { pid: pid });
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (uid === author) success();
|
Posts.editable(uid, pid, function(editable) {
|
||||||
else {
|
if (editable) success();
|
||||||
async.parallel([
|
|
||||||
function(callback) {
|
|
||||||
user.getUserField(uid, 'reputation', function(reputation) {
|
|
||||||
callback(null, reputation >= config.privilege_thresholds.manage_content);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function(callback) {
|
|
||||||
RDB.get('tid:' + tid + ':cid', function(err, cid) {
|
|
||||||
user.isModerator(uid, cid, function(isMod) {
|
|
||||||
callback(null, isMod);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
], function(err, results) {
|
|
||||||
// If any return true, allow the edit
|
|
||||||
for(var x=0,numResults=results.length;x<numResults;x++) {
|
|
||||||
if (results[x]) {
|
|
||||||
success();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Posts.restore = function(uid, pid) {
|
Posts.restore = function(uid, pid) {
|
||||||
RDB.mget(['pid:' + pid + ':tid', 'pid:' + pid + ':uid'], function(err, results) {
|
var success = function() {
|
||||||
var tid = results[0],
|
|
||||||
author = results[1],
|
|
||||||
success = function() {
|
|
||||||
RDB.del('pid:' + pid + ':deleted');
|
RDB.del('pid:' + pid + ':deleted');
|
||||||
|
|
||||||
|
Posts.get_tid_by_pid(pid, function(tid) {
|
||||||
io.sockets.in('topic_' + tid).emit('event:post_restored', { pid: pid });
|
io.sockets.in('topic_' + tid).emit('event:post_restored', { pid: pid });
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (uid === author) success();
|
Posts.editable(uid, pid, function(editable) {
|
||||||
else {
|
if (editable) success();
|
||||||
async.parallel([
|
|
||||||
function(callback) {
|
|
||||||
user.getUserField(uid, 'reputation', function(reputation) {
|
|
||||||
callback(null, reputation >= config.privilege_thresholds.manage_content);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function(callback) {
|
|
||||||
RDB.get('tid:' + tid + ':cid', function(err, cid) {
|
|
||||||
user.isModerator(uid, cid, function(isMod) {
|
|
||||||
callback(null, isMod);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
], function(err, results) {
|
|
||||||
// If any return true, allow the edit
|
|
||||||
for(var x=0,numResults=results.length;x<numResults;x++) {
|
|
||||||
if (results[x]) {
|
|
||||||
success();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}(exports));
|
}(exports));
|
||||||
10
src/user.js
10
src/user.js
@@ -255,11 +255,11 @@ var config = require('../config.js'),
|
|||||||
User.create = function(username, password, email, callback) {
|
User.create = function(username, password, email, callback) {
|
||||||
|
|
||||||
User.exists(username, function(exists) {
|
User.exists(username, function(exists) {
|
||||||
if (exists || email.indexOf('@') === -1 || password.length < 5) return callback(null, -1);
|
if (exists || email.indexOf('@') === -1 /*|| password.length < 5*/) return callback(null, -1);
|
||||||
|
|
||||||
RDB.incr('global:next_user_id', function(err, uid) {
|
RDB.incr('global:next_user_id', function(err, uid) {
|
||||||
RDB.handle(err);
|
RDB.handle(err);
|
||||||
User.hashPassword(password, function(hash) {
|
|
||||||
var gravatar = User.createGravatarURLFromEmail(email);
|
var gravatar = User.createGravatarURLFromEmail(email);
|
||||||
|
|
||||||
RDB.hmset('user:'+uid, {
|
RDB.hmset('user:'+uid, {
|
||||||
@@ -270,7 +270,6 @@ var config = require('../config.js'),
|
|||||||
'website':'',
|
'website':'',
|
||||||
'email' : email,
|
'email' : email,
|
||||||
'joindate' : new Date().getTime(),
|
'joindate' : new Date().getTime(),
|
||||||
'password' : hash,
|
|
||||||
'picture': gravatar,
|
'picture': gravatar,
|
||||||
'gravatarpicture' : gravatar,
|
'gravatarpicture' : gravatar,
|
||||||
'uploadedpicture': '',
|
'uploadedpicture': '',
|
||||||
@@ -294,7 +293,12 @@ var config = require('../config.js'),
|
|||||||
io.sockets.emit('user.latest', {username: username});
|
io.sockets.emit('user.latest', {username: username});
|
||||||
|
|
||||||
callback(null, uid);
|
callback(null, uid);
|
||||||
|
|
||||||
|
if (password) {
|
||||||
|
User.hashPassword(password, function(hash) {
|
||||||
|
RDB.hset('user:'+uid, 'password', hash);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user