mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-14 01:45:47 +01:00
fixing social network logins and refactoring post actions
This commit is contained in:
149
src/posts.js
149
src/posts.js
@@ -27,7 +27,6 @@ marked.setOptions({
|
||||
//compile thread after all data is asynchronously called
|
||||
function generateThread() {
|
||||
if (!post_data || !user_data || !thread_data || !vote_data || !viewer_data) return;
|
||||
console.log(viewer_data);
|
||||
|
||||
var posts = [],
|
||||
main_posts = [],
|
||||
@@ -38,7 +37,8 @@ marked.setOptions({
|
||||
var uid = post_data.uid[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 = {
|
||||
'pid' : pid,
|
||||
'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) {
|
||||
@@ -419,118 +442,46 @@ marked.setOptions({
|
||||
}
|
||||
|
||||
Posts.edit = function(uid, pid, content) {
|
||||
RDB.mget(['pid:' + pid + ':tid', 'pid:' + pid + ':uid'], function(err, results) {
|
||||
var tid = results[0],
|
||||
author = results[1],
|
||||
success = function() {
|
||||
RDB.set('pid:' + pid + ':content', content);
|
||||
RDB.set('pid:' + pid + ':edited', new Date().getTime());
|
||||
RDB.set('pid:' + pid + ':editor', uid);
|
||||
var success = function() {
|
||||
RDB.set('pid:' + pid + ':content', content);
|
||||
RDB.set('pid:' + pid + ':edited', new Date().getTime());
|
||||
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 || '') });
|
||||
};
|
||||
|
||||
if (uid === author) success();
|
||||
else {
|
||||
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.editable(uid, pid, function(editable) {
|
||||
if (editable) success();
|
||||
});
|
||||
}
|
||||
|
||||
Posts.delete = function(uid, pid) {
|
||||
RDB.mget(['pid:' + pid + ':tid', 'pid:' + pid + ':uid'], function(err, results) {
|
||||
var tid = results[0],
|
||||
author = results[1],
|
||||
success = function() {
|
||||
RDB.set('pid:' + pid + ':deleted', 1);
|
||||
var success = function() {
|
||||
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 });
|
||||
};
|
||||
|
||||
if (uid === author) success();
|
||||
else {
|
||||
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.editable(uid, pid, function(editable) {
|
||||
if (editable) success();
|
||||
});
|
||||
}
|
||||
|
||||
Posts.restore = function(uid, pid) {
|
||||
RDB.mget(['pid:' + pid + ':tid', 'pid:' + pid + ':uid'], function(err, results) {
|
||||
var tid = results[0],
|
||||
author = results[1],
|
||||
success = function() {
|
||||
RDB.del('pid:' + pid + ':deleted');
|
||||
var success = function() {
|
||||
RDB.del('pid:' + pid + ':deleted');
|
||||
|
||||
Posts.get_tid_by_pid(pid, function(tid) {
|
||||
io.sockets.in('topic_' + tid).emit('event:post_restored', { pid: pid });
|
||||
};
|
||||
|
||||
if (uid === author) success();
|
||||
else {
|
||||
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.editable(uid, pid, function(editable) {
|
||||
if (editable) success();
|
||||
});
|
||||
}
|
||||
}(exports));
|
||||
72
src/user.js
72
src/user.js
@@ -255,46 +255,50 @@ var config = require('../config.js'),
|
||||
User.create = function(username, password, email, callback) {
|
||||
|
||||
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.handle(err);
|
||||
User.hashPassword(password, function(hash) {
|
||||
var gravatar = User.createGravatarURLFromEmail(email);
|
||||
|
||||
RDB.hmset('user:'+uid, {
|
||||
'username' : username,
|
||||
'fullname': '',
|
||||
'location':'',
|
||||
'birthday':'',
|
||||
'website':'',
|
||||
'email' : email,
|
||||
'joindate' : new Date().getTime(),
|
||||
'password' : hash,
|
||||
'picture': gravatar,
|
||||
'gravatarpicture' : gravatar,
|
||||
'uploadedpicture': '',
|
||||
'reputation': 0,
|
||||
'postcount': 0
|
||||
});
|
||||
|
||||
RDB.set('username:' + username + ':uid', uid);
|
||||
RDB.set('email:' + email +':uid', uid);
|
||||
|
||||
if(email)
|
||||
User.sendConfirmationEmail(email);
|
||||
|
||||
RDB.incr('usercount', function(err, count) {
|
||||
RDB.handle(err);
|
||||
|
||||
io.sockets.emit('user.count', {count: count});
|
||||
});
|
||||
var gravatar = User.createGravatarURLFromEmail(email);
|
||||
|
||||
RDB.lpush('userlist', username);
|
||||
io.sockets.emit('user.latest', {username: username});
|
||||
|
||||
callback(null, uid);
|
||||
RDB.hmset('user:'+uid, {
|
||||
'username' : username,
|
||||
'fullname': '',
|
||||
'location':'',
|
||||
'birthday':'',
|
||||
'website':'',
|
||||
'email' : email,
|
||||
'joindate' : new Date().getTime(),
|
||||
'picture': gravatar,
|
||||
'gravatarpicture' : gravatar,
|
||||
'uploadedpicture': '',
|
||||
'reputation': 0,
|
||||
'postcount': 0
|
||||
});
|
||||
|
||||
RDB.set('username:' + username + ':uid', uid);
|
||||
RDB.set('email:' + email +':uid', uid);
|
||||
|
||||
if(email)
|
||||
User.sendConfirmationEmail(email);
|
||||
|
||||
RDB.incr('usercount', function(err, count) {
|
||||
RDB.handle(err);
|
||||
|
||||
io.sockets.emit('user.count', {count: count});
|
||||
});
|
||||
|
||||
RDB.lpush('userlist', username);
|
||||
io.sockets.emit('user.latest', {username: username});
|
||||
|
||||
callback(null, uid);
|
||||
|
||||
if (password) {
|
||||
User.hashPassword(password, function(hash) {
|
||||
RDB.hset('user:'+uid, 'password', hash);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user