| 
									
										
										
										
											2013-04-23 15:39:23 -04:00
										 |  |  | var	config = require('../config.js'), | 
					
						
							| 
									
										
										
										
											2013-05-01 14:23:57 -04:00
										 |  |  | 	utils = require('./utils.js'), | 
					
						
							| 
									
										
										
										
											2013-04-23 15:39:23 -04:00
										 |  |  | 	RDB = require('./redis.js'), | 
					
						
							| 
									
										
										
										
											2013-04-29 12:22:02 -04:00
										 |  |  | 	crypto = require('crypto'), | 
					
						
							| 
									
										
										
										
											2013-04-23 15:39:23 -04:00
										 |  |  | 	emailjs = require('emailjs'), | 
					
						
							| 
									
										
										
										
											2013-05-03 13:05:57 -04:00
										 |  |  | 	emailjsServer = emailjs.server.connect(config.mailer), | 
					
						
							|  |  |  | 	bcrypt = require('bcrypt'); | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | (function(User) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 12:54:27 -04:00
										 |  |  | 	User.get = function(socket, uid, fields) { | 
					
						
							| 
									
										
										
										
											2013-04-29 12:22:02 -04:00
										 |  |  | 		if (uid > 0) { | 
					
						
							|  |  |  | 			var	keys = [], | 
					
						
							| 
									
										
										
										
											2013-05-01 22:00:49 -04:00
										 |  |  | 				returnData = { | 
					
						
							|  |  |  | 					uid: uid | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2013-04-29 12:22:02 -04:00
										 |  |  | 				removeEmail = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 18:20:22 -04:00
										 |  |  | 			if (!(fields instanceof Array))  | 
					
						
							|  |  |  | 				fields = ['username', 'email', 'joindate']; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-29 12:22:02 -04:00
										 |  |  | 			if (fields.indexOf('picture') !== -1 && fields.indexOf('email') === -1) { | 
					
						
							|  |  |  | 				fields.push('email'); | 
					
						
							|  |  |  | 				removeEmail = true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 18:20:22 -04:00
										 |  |  | 			for(var f = 0, numFields = fields.length; f<numFields; f++) { | 
					
						
							| 
									
										
										
										
											2013-04-29 12:22:02 -04:00
										 |  |  | 				keys.push('uid:' + uid + ':' + fields[f]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			RDB.mget(keys, function(data) { | 
					
						
							|  |  |  | 				for(var x=0,numData=data.length;x<numData;x++) { | 
					
						
							|  |  |  | 					returnData[fields[x]] = data[x]; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2013-04-29 12:22:02 -04:00
										 |  |  | 				if (returnData.picture !== undefined) { | 
					
						
							|  |  |  | 					var	md5sum = crypto.createHash('md5'); | 
					
						
							| 
									
										
										
										
											2013-05-02 11:11:10 -04:00
										 |  |  | 					if (!returnData.email) returnData.email = ''; | 
					
						
							| 
									
										
										
										
											2013-04-29 12:22:02 -04:00
										 |  |  | 					md5sum.update(returnData.email.toLowerCase()); | 
					
						
							|  |  |  | 					returnData.picture = 'http://www.gravatar.com/avatar/' + md5sum.digest('hex') + '?s=24'; | 
					
						
							|  |  |  | 					if (removeEmail) delete returnData.email; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				socket.emit('api:user.get', returnData); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			socket.emit('api:user.get', { | 
					
						
							|  |  |  | 				username: "Anonymous User", | 
					
						
							|  |  |  | 				email: '', | 
					
						
							|  |  |  | 				picture: 'http://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?s=24' | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-04 18:20:22 -04:00
										 |  |  | 	User.getUserData = function(uid, callback) { | 
					
						
							|  |  |  | 		var fields = ['username', 'email', 'joindate', 'picture']; | 
					
						
							|  |  |  | 		var keys = []; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		for(var i = 0, numFields = fields.length; i<numFields; i++) { | 
					
						
							|  |  |  | 			keys.push('uid:' + uid + ':' + fields[i]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		RDB.mget(keys, function(data) { | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			var returnData = { | 
					
						
							|  |  |  | 				uid: uid | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			for(var i=0, numData=data.length; i<numData; i++) { | 
					
						
							|  |  |  | 				returnData[fields[i]] = data[i]; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 			var md5sum = crypto.createHash('md5'); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			md5sum.update(returnData.email.toLowerCase()); | 
					
						
							|  |  |  | 			returnData.picture = 'http://www.gravatar.com/avatar/' + md5sum.digest('hex') + '?s=24'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			callback(returnData); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-03 17:09:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	User.get_gravatars_by_uids = function(uids, size, callback) { | 
					
						
							|  |  |  | 		var keys = []; | 
					
						
							|  |  |  | 		for (var i = 0, ii= uids.length; i<ii; i++) { | 
					
						
							|  |  |  | 			keys.push('uid:' + uids[i] + ':email'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var gravatars = []; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		RDB.mget(keys, function(data) { | 
					
						
							|  |  |  | 			for (var i=0, ii=data.length; i<ii; i++) { | 
					
						
							|  |  |  | 				if (!data[i]) { | 
					
						
							|  |  |  | 					gravatars.push("http://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?s=" + size); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					var	md5sum = crypto.createHash('md5'); | 
					
						
							|  |  |  | 					md5sum.update((data[i]).toLowerCase()); | 
					
						
							|  |  |  | 					gravatars.push('http://www.gravatar.com/avatar/' + md5sum.digest('hex') + '?s=' + size);	 | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			callback(gravatars); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 12:54:27 -04:00
										 |  |  | 	User.login = function(socket, user) { | 
					
						
							| 
									
										
										
										
											2013-04-22 19:01:45 +00:00
										 |  |  | 		if (user.username == null || user.password == null) { | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 			return socket.emit('user.login', {'status': 0, 'message': 'Missing fields'}); | 
					
						
							| 
									
										
										
										
											2013-04-22 19:01:45 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		RDB.get('username:' + user.username + ':uid', function(uid) { | 
					
						
							|  |  |  | 			if (uid == null) { | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 				return socket.emit('user.login', {'status': 0, 'message': 'Username does not exist.'}); | 
					
						
							| 
									
										
										
										
											2013-04-22 19:01:45 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			RDB.get('uid:' + uid + ':password', function(password) { | 
					
						
							|  |  |  | 				if (user.password != password) { | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 					return socket.emit('user.login', {'status': 0, 'message': 'Incorrect username / password combination.'}); | 
					
						
							| 
									
										
										
										
											2013-04-22 19:01:45 +00:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2013-04-24 16:42:12 -04:00
										 |  |  | 					// Start, replace, or extend a session
 | 
					
						
							| 
									
										
										
										
											2013-04-25 12:59:31 -04:00
										 |  |  | 					RDB.get('sess:' + user.sessionID, function(session) { | 
					
						
							| 
									
										
										
										
											2013-04-25 11:04:08 -04:00
										 |  |  | 						if (session !== user.sessionID) { | 
					
						
							| 
									
										
										
										
											2013-04-25 12:59:31 -04:00
										 |  |  | 							RDB.set('sess:' + user.sessionID + ':uid', uid, 60*60*24*14);	// Login valid for two weeks
 | 
					
						
							|  |  |  | 							RDB.set('uid:' + uid + ':session', user.sessionID, 60*60*24*14); | 
					
						
							| 
									
										
										
										
											2013-04-25 11:04:08 -04:00
										 |  |  | 						} else { | 
					
						
							| 
									
										
										
										
											2013-04-25 12:59:31 -04:00
										 |  |  | 							RDB.expire('sess:' + user.sessionID + ':uid', 60*60*24*14);	// Defer expiration to two weeks from now
 | 
					
						
							|  |  |  | 							RDB.expire('uid:' + uid + ':session', 60*60*24*14); | 
					
						
							| 
									
										
										
										
											2013-04-25 11:04:08 -04:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2013-04-24 16:42:12 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-28 21:11:39 -04:00
										 |  |  | 					return socket.emit('user.login', {'status': 1, 'message': 'Logged in!'}); | 
					
						
							| 
									
										
										
										
											2013-04-22 19:01:45 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 21:03:37 -04:00
										 |  |  | 	User.loginViaLocal = function(username, password, next) { | 
					
						
							|  |  |  | 		if (!username || !password) { | 
					
						
							|  |  |  | 			return next({ | 
					
						
							|  |  |  | 				status: 'error', | 
					
						
							|  |  |  | 				message: 'invalid-user' | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			RDB.get('username:' + username + ':uid', function(uid) { | 
					
						
							|  |  |  | 				if (uid == null) { | 
					
						
							|  |  |  | 					return next({ | 
					
						
							|  |  |  | 						status: 'error', | 
					
						
							|  |  |  | 						message: 'invalid-user' | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				RDB.get('uid:' + uid + ':password', function(user_password) { | 
					
						
							| 
									
										
										
										
											2013-05-03 13:05:57 -04:00
										 |  |  | 					bcrypt.compare(password, user_password, function(err, res) { | 
					
						
							|  |  |  | 						if (res === true) { | 
					
						
							|  |  |  | 							next({ | 
					
						
							|  |  |  | 								status: "ok", | 
					
						
							|  |  |  | 								user: { | 
					
						
							|  |  |  | 									uid: uid | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							next({ | 
					
						
							|  |  |  | 								status: 'error', | 
					
						
							|  |  |  | 								message: 'invalid-password' | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2013-05-01 21:03:37 -04:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 11:11:10 -04:00
										 |  |  | 	User.loginViaTwitter = function(twid, handle, callback) { | 
					
						
							|  |  |  | 		User.get_uid_by_twitter_id(twid, function(uid) { | 
					
						
							|  |  |  | 			if (uid !== null) { | 
					
						
							|  |  |  | 				// Existing User
 | 
					
						
							|  |  |  | 				callback(null, { | 
					
						
							|  |  |  | 					uid: uid | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				// New User
 | 
					
						
							|  |  |  | 				User.create(handle, null, null, function(err, uid) { | 
					
						
							|  |  |  | 					if (err !== null) { | 
					
						
							|  |  |  | 						callback(err); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						// Save twitter-specific information to the user
 | 
					
						
							|  |  |  | 						RDB.set('uid:' + uid + ':twid', twid); | 
					
						
							|  |  |  | 						RDB.set('twid:' + twid + ':uid', uid); | 
					
						
							|  |  |  | 						callback(null, { | 
					
						
							|  |  |  | 							uid: uid | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-02 14:47:00 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	User.loginViaGoogle = function(gplusid, handle, email, callback) { | 
					
						
							|  |  |  | 		User.get_uid_by_google_id(gplusid, function(uid) { | 
					
						
							|  |  |  | 			if (uid !== null) { | 
					
						
							|  |  |  | 				// Existing User
 | 
					
						
							|  |  |  | 				callback(null, { | 
					
						
							|  |  |  | 					uid: uid | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				// New User
 | 
					
						
							|  |  |  | 				User.create(handle, null, email, function(err, uid) { | 
					
						
							|  |  |  | 					if (err !== null) { | 
					
						
							|  |  |  | 						callback(err); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						// Save twitter-specific information to the user
 | 
					
						
							|  |  |  | 						RDB.set('uid:' + uid + ':gplusid', gplusid); | 
					
						
							|  |  |  | 						RDB.set('gplusid:' + gplusid + ':uid', uid); | 
					
						
							|  |  |  | 						callback(null, { | 
					
						
							|  |  |  | 							uid: uid | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-05-02 11:11:10 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 15:57:43 -04:00
										 |  |  | 	User.loginViaFacebook = function(fbid, name, email, callback) { | 
					
						
							|  |  |  | 		User.get_uid_by_fbid(fbid, function(uid) { | 
					
						
							|  |  |  | 			if (uid !== null) { | 
					
						
							|  |  |  | 				// Existing User
 | 
					
						
							|  |  |  | 				callback(null, { | 
					
						
							|  |  |  | 					uid: uid | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				// New User
 | 
					
						
							|  |  |  | 				User.create(name, null, email, function(err, uid) { | 
					
						
							|  |  |  | 					if (err !== null) { | 
					
						
							|  |  |  | 						callback(err); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						// Save twitter-specific information to the user
 | 
					
						
							|  |  |  | 						RDB.set('uid:' + uid + ':fbid', fbid); | 
					
						
							|  |  |  | 						RDB.set('fbid:' + fbid + ':uid', uid); | 
					
						
							|  |  |  | 						callback(null, { | 
					
						
							|  |  |  | 							uid: uid | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-28 13:28:20 -04:00
										 |  |  | 	User.logout = function(sessionID, callback) { | 
					
						
							|  |  |  | 		User.get_uid_by_session(sessionID, function(uid) { | 
					
						
							|  |  |  | 			if (uid) { | 
					
						
							| 
									
										
										
										
											2013-04-25 12:59:31 -04:00
										 |  |  | 				RDB.del('sess:' + sessionID + ':uid'); | 
					
						
							| 
									
										
										
										
											2013-04-28 13:28:20 -04:00
										 |  |  | 				RDB.del('uid:' + uid + ':session'); | 
					
						
							| 
									
										
										
										
											2013-04-25 12:59:31 -04:00
										 |  |  | 				callback(true); | 
					
						
							|  |  |  | 			} else callback(false); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-04-22 19:01:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 10:15:55 -04:00
										 |  |  | 	User.create = function(username, password, email, callback) { | 
					
						
							| 
									
										
										
										
											2013-05-02 12:54:27 -04:00
										 |  |  | 		User.exists(null, username, function(exists) { | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 			if (exists) { | 
					
						
							| 
									
										
										
										
											2013-05-02 10:15:55 -04:00
										 |  |  | 				return callback('user-exists', 0); | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			RDB.incr('global:next_user_id', function(uid) { | 
					
						
							|  |  |  | 				RDB.set('username:' + username + ':uid', uid); | 
					
						
							|  |  |  | 				RDB.set('uid:' + uid + ':username', username); | 
					
						
							| 
									
										
										
										
											2013-05-03 13:05:57 -04:00
										 |  |  | 				if (password) { | 
					
						
							|  |  |  | 					bcrypt.genSalt(10, function(err, salt) { | 
					
						
							|  |  |  | 						bcrypt.hash(password, salt, function(err, hash) { | 
					
						
							|  |  |  | 							RDB.set('uid:' + uid + ':password', hash); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-05-04 18:20:22 -04:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2013-05-02 11:11:10 -04:00
										 |  |  | 				if (email) { | 
					
						
							| 
									
										
										
										
											2013-05-05 13:05:05 -04:00
										 |  |  | 					var	confirm_code = utils.generateUUID(), | 
					
						
							|  |  |  | 						confirm_link = config.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 }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 11:11:10 -04:00
										 |  |  | 					RDB.set('uid:' + uid + ':email', email); | 
					
						
							|  |  |  | 					RDB.set('email:' + email, uid); | 
					
						
							| 
									
										
										
										
											2013-05-05 13:05:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					// Email confirmation code
 | 
					
						
							|  |  |  | 					RDB.set('email:' + email + ':confirm', confirm_code, 60*60*2); | 
					
						
							|  |  |  | 					RDB.set('confirm:' + confirm_code + ':email', email, 60*60*2);	// Expire after 2 hours
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// Send intro email w/ confirm code
 | 
					
						
							|  |  |  | 					var message = emailjs.message.create({ | 
					
						
							|  |  |  | 						text: confirm_email_plaintext, | 
					
						
							|  |  |  | 						from: config.mailer.from, | 
					
						
							|  |  |  | 						to: email, | 
					
						
							|  |  |  | 						subject: '[NodeBB] Registration Email Verification', | 
					
						
							|  |  |  | 						attachment: [ | 
					
						
							|  |  |  | 							{ | 
					
						
							|  |  |  | 								data: confirm_email, | 
					
						
							|  |  |  | 								alternative: true | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						] | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					emailjsServer.send(message, function(err, success) { | 
					
						
							|  |  |  | 						if (err) console.log(err); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2013-05-02 11:11:10 -04:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2013-05-04 18:20:22 -04:00
										 |  |  | 				RDB.set('uid:' + uid + ':joindate', new Date().getTime()); | 
					
						
							|  |  |  | 				 | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 				RDB.incr('user:count', function(count) { | 
					
						
							| 
									
										
										
										
											2013-04-22 18:10:24 +00:00
										 |  |  | 					io.sockets.emit('user.count', {count: count}); | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				RDB.lpush('user:users', username); | 
					
						
							| 
									
										
										
										
											2013-04-22 18:10:24 +00:00
										 |  |  | 				io.sockets.emit('user.latest', {username: username}); | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 10:15:55 -04:00
										 |  |  | 				callback(null, uid); | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 12:54:27 -04:00
										 |  |  | 	User.exists = function(socket, username, callback) { | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 		User.get_uid_by_username(username, function(exists) { | 
					
						
							|  |  |  | 			exists = !!exists; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 10:15:55 -04:00
										 |  |  | 			if (callback) callback(exists); | 
					
						
							|  |  |  | 			else socket.emit('user.exists', {exists: exists}); | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-05-02 12:54:27 -04:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	User.count = function(socket) { | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 		RDB.get('user:count', function(count) { | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 			socket.emit('user.count', {count: (count === null) ? 0 : count}); | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-05-02 12:54:27 -04:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	User.latest = function(socket) { | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 		RDB.lrange('user:users', 0, 0, function(username) { | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 			socket.emit('user.latest', {username: username}); | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 		});	 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	User.get_uid_by_username = function(username, callback) { | 
					
						
							|  |  |  | 		RDB.get('username:' + username + ':uid', callback); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 16:28:04 -04:00
										 |  |  | 	User.get_username_by_uid = function(uid, callback) { | 
					
						
							|  |  |  | 		RDB.get('uid:' + uid+ ':username', callback); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-03 11:43:01 -04:00
										 |  |  | 	User.get_usernames_by_uids = function(uids, callback) { | 
					
						
							|  |  |  | 		var userIds = []; | 
					
						
							|  |  |  | 		for(var i=0, ii=uids.length; i<ii; i++) { | 
					
						
							|  |  |  | 			userIds.push('uid:' + uids[i] + ':username'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		RDB.mget(userIds, function(data) { | 
					
						
							|  |  |  | 			callback(data); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-03 18:54:19 +00:00
										 |  |  | 	User.get_user_postdetails = function(uids, callback) { | 
					
						
							|  |  |  | 		var username = [], | 
					
						
							|  |  |  | 			rep = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for(var i=0, ii=uids.length; i<ii; i++) { | 
					
						
							|  |  |  | 			username.push('uid:' + uids[i] + ':username'); | 
					
						
							|  |  |  | 			rep.push('uid:' + uids[i] + ':rep'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		RDB.multi() | 
					
						
							|  |  |  | 			.mget(username) | 
					
						
							|  |  |  | 			.mget(rep) | 
					
						
							|  |  |  | 			.exec(function(err, replies) { | 
					
						
							|  |  |  | 				callback({ | 
					
						
							|  |  |  | 					'username': replies[0], | 
					
						
							|  |  |  | 					'rep' : replies[1] | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-23 15:39:23 -04:00
										 |  |  | 	User.get_uid_by_email = function(email, callback) { | 
					
						
							|  |  |  | 		RDB.get('email:' + email, callback) | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 17:14:05 -04:00
										 |  |  | 	User.get_uid_by_session = function(session, callback) { | 
					
						
							| 
									
										
										
										
											2013-04-25 12:59:31 -04:00
										 |  |  | 		RDB.get('sess:' + session + ':uid', callback); | 
					
						
							| 
									
										
										
										
											2013-04-24 17:14:05 -04:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 11:11:10 -04:00
										 |  |  | 	User.get_uid_by_twitter_id = function(twid, callback) { | 
					
						
							|  |  |  | 		RDB.get('twid:' + twid + ':uid', function(uid) { | 
					
						
							|  |  |  | 			callback(uid); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 14:47:00 -04:00
										 |  |  | 	User.get_uid_by_google_id = function(gplusid, callback) { | 
					
						
							|  |  |  | 		RDB.get('gplusid:' + gplusid + ':uid', function(uid) { | 
					
						
							|  |  |  | 			callback(uid); | 
					
						
							|  |  |  | 		});	 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 15:57:43 -04:00
										 |  |  | 	User.get_uid_by_fbid = function(fbid, callback) { | 
					
						
							|  |  |  | 		RDB.get('fbid:' + fbid + ':uid', function(uid) { | 
					
						
							|  |  |  | 			callback(uid); | 
					
						
							|  |  |  | 		});	 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 21:03:37 -04:00
										 |  |  | 	User.session_ping = function(sessionID, uid) { | 
					
						
							|  |  |  | 		// Start, replace, or extend a session
 | 
					
						
							|  |  |  | 		RDB.get('sess:' + sessionID, function(session) { | 
					
						
							|  |  |  | 			RDB.set('sess:' + sessionID + ':uid', uid, 60*60*24*14);	// Login valid for two weeks
 | 
					
						
							|  |  |  | 			RDB.set('uid:' + uid + ':session', sessionID, 60*60*24*14); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-23 21:13:01 -04:00
										 |  |  | 	User.reset = { | 
					
						
							| 
									
										
										
										
											2013-05-02 12:54:27 -04:00
										 |  |  | 		validate: function(socket, code, callback) { | 
					
						
							| 
									
										
										
										
											2013-04-23 23:28:34 -04:00
										 |  |  | 			if (typeof callback !== 'function') callback = undefined; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-23 21:13:01 -04:00
										 |  |  | 			RDB.get('reset:' + code + ':uid', function(uid) { | 
					
						
							|  |  |  | 				if (uid !== null) { | 
					
						
							|  |  |  | 					RDB.get('reset:' + code + ':expiry', function(expiry) { | 
					
						
							| 
									
										
										
										
											2013-04-23 23:28:34 -04:00
										 |  |  | 						if (expiry >= +new Date()/1000|0) { | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 							if (!callback) socket.emit('user:reset.valid', { valid: true }); | 
					
						
							| 
									
										
										
										
											2013-04-23 23:28:34 -04:00
										 |  |  | 							else callback(true); | 
					
						
							|  |  |  | 						} else { | 
					
						
							| 
									
										
										
										
											2013-04-23 22:35:03 -04:00
										 |  |  | 							// Expired, delete from db
 | 
					
						
							|  |  |  | 							RDB.del('reset:' + code + ':uid'); | 
					
						
							|  |  |  | 							RDB.del('reset:' + code + ':expiry'); | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 							if (!callback) socket.emit('user:reset.valid', { valid: false }); | 
					
						
							| 
									
										
										
										
											2013-04-23 23:28:34 -04:00
										 |  |  | 							else callback(false); | 
					
						
							| 
									
										
										
										
											2013-04-23 22:35:03 -04:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2013-04-23 21:13:01 -04:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2013-04-23 23:28:34 -04:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 					if (!callback) socket.emit('user:reset.valid', { valid: false }); | 
					
						
							| 
									
										
										
										
											2013-04-23 23:28:34 -04:00
										 |  |  | 					else callback(false); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-04-23 21:13:01 -04:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2013-05-02 12:54:27 -04:00
										 |  |  | 		send: function(socket, email) { | 
					
						
							| 
									
										
										
										
											2013-04-23 21:13:01 -04:00
										 |  |  | 			User.get_uid_by_email(email, function(uid) { | 
					
						
							|  |  |  | 				if (uid !== null) { | 
					
						
							|  |  |  | 					// Generate a new reset code
 | 
					
						
							|  |  |  | 					var reset_code = utils.generateUUID(); | 
					
						
							|  |  |  | 					RDB.set('reset:' + reset_code + ':uid', uid); | 
					
						
							|  |  |  | 					RDB.set('reset:' + reset_code + ':expiry', (60*60)+new Date()/1000|0);	// Active for one hour
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					var reset_link = config.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 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					var message = emailjs.message.create({ | 
					
						
							|  |  |  | 						text: reset_email_plaintext, | 
					
						
							|  |  |  | 						from: config.mailer.from, | 
					
						
							|  |  |  | 						to: email, | 
					
						
							|  |  |  | 						subject: 'Password Reset Requested', | 
					
						
							|  |  |  | 						attachment: [ | 
					
						
							|  |  |  | 							{ | 
					
						
							|  |  |  | 								data: reset_email, | 
					
						
							|  |  |  | 								alternative: true | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						] | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					emailjsServer.send(message, function(err, success) { | 
					
						
							|  |  |  | 						if (err === null) { | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 							socket.emit('user.send_reset', { | 
					
						
							| 
									
										
										
										
											2013-04-23 21:13:01 -04:00
										 |  |  | 								status: "ok", | 
					
						
							|  |  |  | 								message: "code-sent", | 
					
						
							|  |  |  | 								email: email | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						} else { | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 							socket.emit('user.send_reset', { | 
					
						
							| 
									
										
										
										
											2013-04-23 21:13:01 -04:00
										 |  |  | 								status: "error", | 
					
						
							|  |  |  | 								message: "send-failed" | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 							throw new Error(err); | 
					
						
							| 
									
										
										
										
											2013-04-23 15:39:23 -04:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2013-04-23 21:13:01 -04:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 					socket.emit('user.send_reset', { | 
					
						
							| 
									
										
										
										
											2013-04-23 21:13:01 -04:00
										 |  |  | 						status: "error", | 
					
						
							|  |  |  | 						message: "invalid-email", | 
					
						
							|  |  |  | 						email: email | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-04-23 23:28:34 -04:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2013-05-02 12:54:27 -04:00
										 |  |  | 		commit: function(socket, code, password) { | 
					
						
							| 
									
										
										
										
											2013-04-23 23:28:34 -04:00
										 |  |  | 			this.validate(code, function(validated) { | 
					
						
							|  |  |  | 				if (validated) { | 
					
						
							|  |  |  | 					RDB.get('reset:' + code + ':uid', function(uid) { | 
					
						
							|  |  |  | 						RDB.set('uid:' + uid + ':password', password); | 
					
						
							|  |  |  | 						RDB.del('reset:' + code + ':uid'); | 
					
						
							|  |  |  | 						RDB.del('reset:' + code + ':expiry'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 						socket.emit('user:reset.commit', { status: 'ok' }); | 
					
						
							| 
									
										
										
										
											2013-04-23 23:28:34 -04:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-04-23 21:13:01 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-04-23 12:06:22 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-22 17:31:51 -04:00
										 |  |  | 	User.email = { | 
					
						
							| 
									
										
										
										
											2013-05-02 12:54:27 -04:00
										 |  |  | 		exists: function(socket, email, callback) { | 
					
						
							| 
									
										
										
										
											2013-04-23 15:39:23 -04:00
										 |  |  | 			User.get_uid_by_email(email, function(exists) { | 
					
						
							| 
									
										
										
										
											2013-04-22 17:31:51 -04:00
										 |  |  | 				exists = !!exists; | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 				if (typeof callback !== 'function') socket.emit('user.email.exists', { exists: exists }); | 
					
						
							| 
									
										
										
										
											2013-04-23 12:06:22 -04:00
										 |  |  | 				else callback(exists); | 
					
						
							| 
									
										
										
										
											2013-04-22 17:31:51 -04:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-05-05 13:05:05 -04:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		confirm: function(code, callback) { | 
					
						
							|  |  |  | 			RDB.get('confirm:' + code + ':email', function(email) { | 
					
						
							|  |  |  | 				if (email !== null) { | 
					
						
							|  |  |  | 					RDB.set('email:' + email + ':confirm', true); | 
					
						
							|  |  |  | 					RDB.del('confirm:' + code + ':email'); | 
					
						
							|  |  |  | 					callback({ | 
					
						
							|  |  |  | 						status: 'ok' | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					callback({ | 
					
						
							|  |  |  | 						status: 'not_ok' | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-04-22 17:31:51 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-04-25 16:27:22 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	User.active = { | 
					
						
							| 
									
										
										
										
											2013-05-02 12:54:27 -04:00
										 |  |  | 		get_record : function(socket) { | 
					
						
							| 
									
										
										
										
											2013-05-01 18:01:02 +00:00
										 |  |  | 			RDB.mget(['global:active_user_record', 'global:active_user_record_date'], function(data) { | 
					
						
							|  |  |  | 				socket.emit('api:user.active.get_record', {record: data[0], timestamp: data[1]}); | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-25 16:27:22 -04:00
										 |  |  | 		get: function(callback) { | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 			function user_record(total) { | 
					
						
							|  |  |  | 				RDB.get('global:active_user_record', function(record) { | 
					
						
							|  |  |  | 					if (total > record) { | 
					
						
							|  |  |  | 						RDB.set('global:active_user_record', total); | 
					
						
							| 
									
										
										
										
											2013-05-01 18:01:02 +00:00
										 |  |  | 						RDB.set('global:active_user_record_date', new Date().getTime()); | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-25 16:27:22 -04:00
										 |  |  | 			RDB.keys('active:*', function(active) { | 
					
						
							|  |  |  | 				var	returnObj = { | 
					
						
							|  |  |  | 						users: 0, | 
					
						
							|  |  |  | 						anon: 0, | 
					
						
							|  |  |  | 						uids: [] | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					keys = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-28 13:28:20 -04:00
										 |  |  | 				if (active.length > 0) { | 
					
						
							|  |  |  | 					for(var a in active) { | 
					
						
							|  |  |  | 						keys.push('sess:' + active[a].split(':')[1] + ':uid'); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2013-04-25 16:27:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-28 13:28:20 -04:00
										 |  |  | 					RDB.mget(keys, function(uids) { | 
					
						
							|  |  |  | 						for(var u in uids) { | 
					
						
							|  |  |  | 							if (uids[u] !== null) { | 
					
						
							|  |  |  | 								if (returnObj.uids.indexOf(uids[u]) === -1) { | 
					
						
							|  |  |  | 									returnObj.users++; | 
					
						
							|  |  |  | 									returnObj.uids.push(uids[u]); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							} else { | 
					
						
							|  |  |  | 								returnObj.anon++; | 
					
						
							| 
									
										
										
										
											2013-04-25 16:27:22 -04:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 16:14:09 +00:00
										 |  |  | 						user_record(returnObj.anon + returnObj.users); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-28 13:28:20 -04:00
										 |  |  | 						if (callback === undefined) { | 
					
						
							| 
									
										
										
										
											2013-04-28 16:04:00 -04:00
										 |  |  | 							io.sockets.emit('api:user.active.get', returnObj) | 
					
						
							| 
									
										
										
										
											2013-04-28 13:28:20 -04:00
										 |  |  | 						} else { | 
					
						
							|  |  |  | 							callback(returnObj); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2013-04-28 16:04:00 -04:00
										 |  |  | 					io.sockets.emit('api:user.active.get', returnObj) | 
					
						
							| 
									
										
										
										
											2013-04-28 13:28:20 -04:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-04-25 16:27:22 -04:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		register: function(sessionID) { | 
					
						
							| 
									
										
										
										
											2013-04-28 13:28:20 -04:00
										 |  |  | 			RDB.set('active:' + sessionID, '', 60*10);	// Active state persists for 10 minutes
 | 
					
						
							| 
									
										
										
										
											2013-04-28 15:56:44 -04:00
										 |  |  | 			this.get(); | 
					
						
							| 
									
										
										
										
											2013-04-25 16:27:22 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | }(exports)); |