mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	init, just some testing
This commit is contained in:
		
							
								
								
									
										67
									
								
								src/user.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								src/user.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,67 @@ | ||||
| var RDB = require('../RedisDB.js'); | ||||
|  | ||||
| (function(User) { | ||||
| 	var current_uid; | ||||
|  | ||||
| 	User.create = function(username, password) { | ||||
| 		if (current_uid) { | ||||
| 			global.socket.emit('user.create', {'status': 0, 'message': 'Only anonymous users can register a new account.'}); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		if (username == null || password == null) { | ||||
| 			global.socket.emit('user.create', {'status': 0, 'message': 'Missing fields'}); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
|  | ||||
| 		User.exists(username, function(exists) { | ||||
| 			if (exists) { | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			RDB.incr('global:next_user_id', function(uid) { | ||||
| 				RDB.set('username:' + username + ':uid', uid); | ||||
| 				RDB.set('uid:' + uid + ':username', username); | ||||
| 				RDB.set('uid:' + uid + ':password', password); | ||||
| 				 | ||||
| 				RDB.incr('user:count', function(count) { | ||||
| 					io.sockets.emit('user.count', {count: count}); | ||||
| 				}); | ||||
|  | ||||
| 				RDB.lpush('user:users', username); | ||||
| 				io.sockets.emit('user.latest', {username: username}); | ||||
|  | ||||
| 				global.socket.emit('user.create', {'status': 1}); | ||||
| 			}); | ||||
| 		}); | ||||
| 	}; | ||||
|  | ||||
|  | ||||
| 	User.exists = function(username, callback) { | ||||
| 		User.get_uid_by_username(username, function(exists) { | ||||
| 			exists = !!exists; | ||||
| 			global.socket.emit('user.exists', {exists: exists}) | ||||
|  | ||||
| 			if (callback) { | ||||
| 				callback(exists); | ||||
| 			} | ||||
| 		}); | ||||
| 	}; | ||||
| 	User.count = function() { | ||||
| 		RDB.get('user:count', function(count) { | ||||
| 			global.socket.emit('user.count', {count: (count === null) ? 0 : count}); | ||||
| 		}); | ||||
| 	}; | ||||
| 	User.latest = function() { | ||||
| 		RDB.lrange('user:users', 0, 0, function(username) { | ||||
| 			global.socket.emit('user.latest', {username: username}); | ||||
| 		});	 | ||||
| 	} | ||||
|  | ||||
| 	User.get_uid_by_username = function(username, callback) { | ||||
| 		RDB.get('username:' + username + ':uid', callback); | ||||
| 	}; | ||||
|  | ||||
|  | ||||
| }(exports)); | ||||
		Reference in New Issue
	
	Block a user