From 27cb837b08e77a6fd5196c185dc50d16b3995ffd Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Thu, 19 Sep 2013 12:29:25 -0400 Subject: [PATCH] closes #303 --- src/categories.js | 2 -- src/login.js | 10 -------- src/notifications.js | 1 - src/routes/authentication.js | 15 ++++++------ src/routes/user.js | 2 +- src/topics.js | 1 - src/user.js | 45 ++++++++---------------------------- src/webserver.js | 7 ------ 8 files changed, 17 insertions(+), 66 deletions(-) diff --git a/src/categories.js b/src/categories.js index d72e11b10b..c05299fcd5 100644 --- a/src/categories.js +++ b/src/categories.js @@ -31,8 +31,6 @@ var RDB = require('./redis.js'), }; RDB.hmset('category:' + cid, category); - RDB.set('categoryslug:' + slug + ':cid', cid); - callback(null, category); }); }; diff --git a/src/login.js b/src/login.js index 96ca0e8023..131ad3b94a 100644 --- a/src/login.js +++ b/src/login.js @@ -150,14 +150,4 @@ var user = require('./user.js'), }); } - Login.logout = function(sessionID, callback) { - user.get_uid_by_session(sessionID, function(uid) { - if (uid) { - RDB.del('sess:' + sessionID + ':uid'); - RDB.del('uid:' + uid + ':session'); - callback(true); - } else callback(false); - }); - } - }(exports)); \ No newline at end of file diff --git a/src/notifications.js b/src/notifications.js index b3fdd4eafa..c2fb26cd26 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -52,7 +52,6 @@ var RDB = require('./redis.js'), (function(uid) { notifications.remove_by_uniqueId(notif_data.uniqueId, uid, function() { RDB.zadd('uid:' + uid + ':notifications:unread', notif_data.score, nid); - RDB.set('uid:' + uid + ':notifications:flag', 1); global.io.sockets. in ('uid_' + uid).emit('event:new_notification'); if (callback) callback(true); }); diff --git a/src/routes/authentication.js b/src/routes/authentication.js index da93113b01..f2b5212cc4 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -94,14 +94,13 @@ app.get('/logout', function(req, res) { if (req.user && req.user.uid > 0) { winston.info('[Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')'); - login_module.logout(req.sessionID, function(logout) { - req.logout(); - app.build_header({ - req: req, - res: res - }, function(err, header) { - res.send(header + templates['logout'] + templates['footer']); - }); + + req.logout(); + app.build_header({ + req: req, + res: res + }, function(err, header) { + res.send(header + templates['logout'] + templates['footer']); }); } else res.redirect('/'); }); diff --git a/src/routes/user.js b/src/routes/user.js index cce4c71a4b..8fdfd9a85a 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -367,7 +367,7 @@ var user = require('./../user.js'), }); return; } - console.log(uid, callerUID); + if (uid !== callerUID || callerUID === '0') { res.json(403, { error: 'Not allowed!' diff --git a/src/topics.js b/src/topics.js index f0cd83a1df..49d2274b86 100644 --- a/src/topics.js +++ b/src/topics.js @@ -670,7 +670,6 @@ schema = require('./schema.js'), }); topicSearch.index(title, tid); - RDB.set('topicslug:' + slug + ':tid', tid); user.addTopicIdToUser(uid, tid); diff --git a/src/user.js b/src/user.js index c3e700cd20..ac0fec809d 100644 --- a/src/user.js +++ b/src/user.js @@ -705,15 +705,6 @@ var utils = require('./../public/src/utils.js'), }); }; - User.get_uid_by_session = function(session, callback) { - RDB.get('sess:' + session + ':uid', function(err, data) { - if (err) { - RDB.handle(err); - } - callback(data); - }); - }; - User.get_uid_by_twitter_id = function(twid, callback) { RDB.hget('twid:uid', twid, function(err, uid) { if (err) { @@ -741,24 +732,6 @@ var utils = require('./../public/src/utils.js'), }); } - User.session_ping = function(sessionID, uid) { - // Start, replace, or extend a session - RDB.get('sess:' + sessionID, function(err, session) { - if (err) { - RDB.handle(err); - } - - var expiry = 60 * 60 * 24 * 14, // Login valid for two weeks - sess_key = 'sess:' + sessionID + ':uid', - uid_key = 'uid:' + uid + ':session'; - - RDB.set(sess_key, uid); - RDB.expire(sess_key, expiry); - RDB.set(uid_key, sessionID); - RDB.expire(uid_key, expiry); - }); - } - User.isModerator = function(uid, cid, callback) { RDB.sismember('cid:' + cid + ':moderators', uid, function(err, exists) { RDB.handle(err); @@ -781,13 +754,13 @@ var utils = require('./../public/src/utils.js'), callback = null; } - RDB.get('reset:' + code + ':uid', function(err, uid) { + RDB.hget('reset:uid', code, function(err, uid) { if (err) { RDB.handle(err); } if (uid !== null) { - RDB.get('reset:' + code + ':expiry', function(err, expiry) { + RDB.hget('reset:expiry', code, function(err, expiry) { if (err) { RDB.handle(err); } @@ -802,8 +775,8 @@ var utils = require('./../public/src/utils.js'), } } else { // Expired, delete from db - RDB.del('reset:' + code + ':uid'); - RDB.del('reset:' + code + ':expiry'); + RDB.hdel('reset:uid', code); + RDB.hdel('reset:expiry', code); if (!callback) { socket.emit('user:reset.valid', { valid: false @@ -829,8 +802,8 @@ var utils = require('./../public/src/utils.js'), 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 + RDB.hset('reset:uid', reset_code, uid); + RDB.hset('reset:expiry', reset_code, (60 * 60) + new Date() / 1000 | 0); // Active for one hour var reset_link = nconf.get('url') + 'reset/' + reset_code, reset_email = global.templates['emails/reset'].parse({ @@ -879,7 +852,7 @@ var utils = require('./../public/src/utils.js'), commit: function(socket, code, password) { this.validate(socket, code, function(validated) { if (validated) { - RDB.get('reset:' + code + ':uid', function(err, uid) { + RDB.hget('reset:uid', code, function(err, uid) { if (err) { RDB.handle(err); } @@ -888,8 +861,8 @@ var utils = require('./../public/src/utils.js'), User.setUserField(uid, 'password', hash); }); - RDB.del('reset:' + code + ':uid'); - RDB.del('reset:' + code + ':expiry'); + RDB.hdel('reset:uid', code); + RDB.hdel('reset:expiry', code); socket.emit('user:reset.commit', { status: 'ok' diff --git a/src/webserver.js b/src/webserver.js index 7306e25296..6a85c3f71e 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -126,13 +126,6 @@ var express = require('express'), nconf.set('https', req.secure); - // Don't bother with session handling for API requests - if (/^\/api\//.test(req.url)) return next(); - - if (req.user && req.user.uid) { - user.session_ping(req.sessionID, req.user.uid); - } - next(); });