mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +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 | 		//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], | 				RDB.set('pid:' + pid + ':content', content); | ||||||
| 				author = results[1], | 				RDB.set('pid:' + pid + ':edited', new Date().getTime()); | ||||||
| 				success = function() { | 				RDB.set('pid:' + pid + ':editor', uid); | ||||||
| 					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 || '') }); | 					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) { | 	Posts.delete = function(uid, pid) { | ||||||
| 		RDB.mget(['pid:' + pid + ':tid', 'pid:' + pid + ':uid'], function(err, results) { | 		var	success = function() { | ||||||
| 			var	tid = results[0], | 				RDB.set('pid:' + pid + ':deleted', 1); | ||||||
| 				author = results[1], |  | ||||||
| 				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 }); | 					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) { | 	Posts.restore = function(uid, pid) { | ||||||
| 		RDB.mget(['pid:' + pid + ':tid', 'pid:' + pid + ':uid'], function(err, results) { | 		var	success = function() { | ||||||
| 			var	tid = results[0], | 				RDB.del('pid:' + pid + ':deleted'); | ||||||
| 				author = results[1], |  | ||||||
| 				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 }); | 					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)); | }(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.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); |  | ||||||
|  |  | ||||||
| 					RDB.hmset('user:'+uid, { | 				var gravatar = User.createGravatarURLFromEmail(email); | ||||||
| 						'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}); |  | ||||||
| 					}); |  | ||||||
|  |  | ||||||
| 					RDB.lpush('userlist', username); | 				RDB.hmset('user:'+uid, { | ||||||
| 					io.sockets.emit('user.latest', {username: username}); | 					'username' : username, | ||||||
|  | 					'fullname': '', | ||||||
| 					callback(null, uid); | 					'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