From 6d79521922b72f0d09a5a2228e9713363052c44b Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 2 Dec 2013 22:33:55 -0500 Subject: [PATCH] moved connect-redis to the redis.db file, expose the sessionStore from redis.js db file, do the same for mongo db with mongo-connect --- src/database/redis.js | 8 ++++++++ src/login.js | 1 - src/routes/authentication.js | 1 - src/webserver.js | 16 ++-------------- src/websockets.js | 10 +--------- 5 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/database/redis.js b/src/database/redis.js index e6f7ef8e13..462bd46eb5 100644 --- a/src/database/redis.js +++ b/src/database/redis.js @@ -6,6 +6,9 @@ redis = require('redis'), winston = require('winston'), nconf = require('nconf'), + express = require('express'), + connectRedis = require('connect-redis')(express), + redis_socket_or_host = nconf.get('redis:host'), utils = require('./../../public/src/utils.js'); @@ -17,6 +20,11 @@ redisClient = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host')); } + module.sessionStore = new connectRedis({ + client: redisClient, + ttl: 60 * 60 * 24 * 30 + }); + module.client = redisClient; module.type = 'redis'; diff --git a/src/login.js b/src/login.js index d20fec6c30..adce1f8bfc 100644 --- a/src/login.js +++ b/src/login.js @@ -43,7 +43,6 @@ var user = require('./user'), } if (res) { - console.log('logged in', uid); next(null, { user: { uid: uid diff --git a/src/routes/authentication.js b/src/routes/authentication.js index 14c3fb5e98..ba2aae842d 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -15,7 +15,6 @@ passport.use(new passportLocal(function(user, password, next) { login_module.loginViaLocal(user, password, function(err, login) { if (!err) { - console.log('LOGGED IN'); next(null, login.user); } else { next(null, false, err); diff --git a/src/webserver.js b/src/webserver.js index 60c5e87e62..58bd187ae7 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -5,7 +5,6 @@ var path = require('path'), express_namespace = require('express-namespace'), WebServer = express(), server = require('http').createServer(WebServer), - RedisStore = require('connect-redis')(express), nconf = require('nconf'), winston = require('winston'), validator = require('validator'), @@ -142,19 +141,8 @@ var path = require('path'), app.use(express.cookieParser()); // If you want to parse cookies (res.cookies) // TODO : this uses redis - /*app.use(express.session({ - store: new RedisStore({ - client: RDB, - ttl: 60 * 60 * 24 * 30 - }), - secret: nconf.get('secret'), - key: 'express.sid', - cookie: { - maxAge: 60 * 60 * 24 * 30 * 1000 // 30 days - } - }));*/ - - app.use(express.cookieSession({ + app.use(express.session({ + store: db.sessionStore, secret: nconf.get('secret'), key: 'express.sid', cookie: { diff --git a/src/websockets.js b/src/websockets.js index f5ec7a2628..19324e695e 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -12,14 +12,6 @@ var cookie = require('cookie'), RedisStoreLib = require('connect-redis')(express), db = require('./database'), - redis = require('redis'), - redisClient = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host')), - - RedisStore = new RedisStoreLib({ - client: redisClient, - ttl: 60 * 60 * 24 * 14 - }), - user = require('./user'), Groups = require('./groups'), posts = require('./posts'), @@ -74,7 +66,7 @@ websockets.init = function(io) { // Validate the session, if present socketCookieParser(hs, {}, function(err) { sessionID = socket.handshake.signedCookies["express.sid"]; - RedisStore.get(sessionID, function(err, sessionData) { + db.sessionStore.get(sessionID, function(err, sessionData) { if (!err && sessionData && sessionData.passport && sessionData.passport.user) { uid = users[sessionID] = sessionData.passport.user; } else {