From 71125fd1e284336f85d4e4425bbc848ce4c48cf5 Mon Sep 17 00:00:00 2001 From: akhoury Date: Sun, 1 Dec 2013 10:43:48 -0500 Subject: [PATCH 1/5] adding webstorm's .idea folder to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c6ab6e2a8d..6c0c33d689 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ public/css/*.css *.sublime-project *.sublime-workspace .project +.idea *.swp Vagrantfile .vagrant From 1aa1ddb4ec63fbc8694868f89a6a961657cc7fc0 Mon Sep 17 00:00:00 2001 From: akhoury Date: Sun, 1 Dec 2013 10:52:50 -0500 Subject: [PATCH 2/5] added plugin hook > action:user.create on user creation --- src/user.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/user.js b/src/user.js index 090f4d3758..22bb98cac7 100644 --- a/src/user.js +++ b/src/user.js @@ -9,6 +9,7 @@ var bcrypt = require('bcrypt'), sanitize = require('validator').sanitize, utils = require('./../public/src/utils'), + plugins = require('./plugins'), RDB = require('./redis'), meta = require('./meta'), emailjsServer = emailjs.server.connect(meta.config['email:smtp:host'] || '127.0.0.1'), @@ -103,6 +104,7 @@ var bcrypt = require('bcrypt'), User.sendConfirmationEmail(email); } + plugins.fireHook('action:user.create', {uid: uid, username: username, email: email, picture: gravatar, timestamp: timestamp}); RDB.incr('usercount'); RDB.zadd('users:joindate', timestamp, uid); From 0f53749e70f69801f4e9bb7f894c8b0572024237 Mon Sep 17 00:00:00 2001 From: akhoury Date: Sun, 1 Dec 2013 10:53:59 -0500 Subject: [PATCH 3/5] websockets.js to follow same pattern to avoid circular dependencies --- src/websockets.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/websockets.js b/src/websockets.js index 3f2fb5e4a3..87af2b8029 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -5,6 +5,7 @@ var cookie = require('cookie'), async = require('async'), fs = require('fs'), nconf = require('nconf'), + gravatar = require('gravatar'), winston = require('winston'), RedisStoreLib = require('connect-redis')(express), @@ -34,12 +35,13 @@ var cookie = require('cookie'), }, plugins = require('./plugins'); +(function(websockets) { var users = {}, userSockets = {}, rooms = {}; -module.exports.logoutUser = function(uid) { +websockets.logoutUser = function(uid) { if(userSockets[uid] && userSockets[uid].length) { for(var i=0; i< userSockets[uid].length; ++i) { userSockets[uid][i].emit('event:disconnect'); @@ -55,9 +57,9 @@ module.exports.logoutUser = function(uid) { function isUserOnline(uid) { return !!userSockets[uid] && userSockets[uid].length > 0; } -module.exports.isUserOnline = isUserOnline; +websockets.isUserOnline = isUserOnline; -module.exports.init = function(io) { +websockets.exports.init = function(io) { io.sockets.on('connection', function(socket) { var hs = socket.handshake, @@ -222,9 +224,9 @@ module.exports.init = function(io) { uid: 0, username: "Anonymous User", email: '', - picture: require('gravatar').url('', { + picture: gravatar.url('', { s: '24' - }, https = nconf.get('https')) + }, nconf.get('https')) }); } @@ -475,12 +477,12 @@ module.exports.init = function(io) { }); socket.on('api:user.getOnlineAnonCount', function(data, callback) { - callback(module.exports.getOnlineAnonCount()); + callback(websockets.getOnlineAnonCount()); }); - module.exports.getOnlineAnonCount = function () { + websockets.getOnlineAnonCount = function () { return userSockets[0] ? userSockets[0].length : 0; - } + }; function emitOnlineUserCount() { var anon = userSockets[0] ? userSockets[0].length : 0; @@ -947,7 +949,7 @@ module.exports.init = function(io) { userSockets[theirid][i].emit('event:banned'); } } - module.exports.logoutUser(theirid); + websockets.logoutUser(theirid); } }); } @@ -1114,7 +1116,7 @@ module.exports.init = function(io) { }); } - module.exports.emitUserCount = function() { + websockets.emitUserCount = function() { RDB.get('usercount', function(err, count) { io.sockets.emit('user.count', { count: count @@ -1122,9 +1124,10 @@ module.exports.init = function(io) { }); }; - module.exports.in = function(room) { + websockets.in = function(room) { return io.sockets.in(room); }; } +})(module.exports); From 52700fbe164efb9a28f91bb3e00f83949087e17d Mon Sep 17 00:00:00 2001 From: akhoury Date: Sun, 1 Dec 2013 10:56:29 -0500 Subject: [PATCH 4/5] websockets.js to 'use strict'; --- src/websockets.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/websockets.js b/src/websockets.js index 87af2b8029..a9339862ac 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -1,3 +1,4 @@ +'use strict'; var cookie = require('cookie'), express = require('express'), From 2733198f9ecaec1be93261ac73b26fddfa1b4992 Mon Sep 17 00:00:00 2001 From: akhoury Date: Sun, 1 Dec 2013 11:05:10 -0500 Subject: [PATCH 5/5] oops --- src/websockets.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/websockets.js b/src/websockets.js index a9339862ac..5ab754f222 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -60,7 +60,7 @@ function isUserOnline(uid) { } websockets.isUserOnline = isUserOnline; -websockets.exports.init = function(io) { +websockets.init = function(io) { io.sockets.on('connection', function(socket) { var hs = socket.handshake,