v1.18.x
Baris Usakli 12 years ago
parent 047fcbe63f
commit 27cb837b08

@ -31,8 +31,6 @@ var RDB = require('./redis.js'),
}; };
RDB.hmset('category:' + cid, category); RDB.hmset('category:' + cid, category);
RDB.set('categoryslug:' + slug + ':cid', cid);
callback(null, category); callback(null, category);
}); });
}; };

@ -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)); }(exports));

@ -52,7 +52,6 @@ var RDB = require('./redis.js'),
(function(uid) { (function(uid) {
notifications.remove_by_uniqueId(notif_data.uniqueId, uid, function() { notifications.remove_by_uniqueId(notif_data.uniqueId, uid, function() {
RDB.zadd('uid:' + uid + ':notifications:unread', notif_data.score, nid); 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'); global.io.sockets. in ('uid_' + uid).emit('event:new_notification');
if (callback) callback(true); if (callback) callback(true);
}); });

@ -94,14 +94,13 @@
app.get('/logout', function(req, res) { app.get('/logout', function(req, res) {
if (req.user && req.user.uid > 0) { if (req.user && req.user.uid > 0) {
winston.info('[Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')'); winston.info('[Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')');
login_module.logout(req.sessionID, function(logout) {
req.logout(); req.logout();
app.build_header({ app.build_header({
req: req, req: req,
res: res res: res
}, function(err, header) { }, function(err, header) {
res.send(header + templates['logout'] + templates['footer']); res.send(header + templates['logout'] + templates['footer']);
});
}); });
} else res.redirect('/'); } else res.redirect('/');
}); });

@ -367,7 +367,7 @@ var user = require('./../user.js'),
}); });
return; return;
} }
console.log(uid, callerUID);
if (uid !== callerUID || callerUID === '0') { if (uid !== callerUID || callerUID === '0') {
res.json(403, { res.json(403, {
error: 'Not allowed!' error: 'Not allowed!'

@ -670,7 +670,6 @@ schema = require('./schema.js'),
}); });
topicSearch.index(title, tid); topicSearch.index(title, tid);
RDB.set('topicslug:' + slug + ':tid', tid);
user.addTopicIdToUser(uid, tid); user.addTopicIdToUser(uid, tid);

@ -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) { User.get_uid_by_twitter_id = function(twid, callback) {
RDB.hget('twid:uid', twid, function(err, uid) { RDB.hget('twid:uid', twid, function(err, uid) {
if (err) { 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) { User.isModerator = function(uid, cid, callback) {
RDB.sismember('cid:' + cid + ':moderators', uid, function(err, exists) { RDB.sismember('cid:' + cid + ':moderators', uid, function(err, exists) {
RDB.handle(err); RDB.handle(err);
@ -781,13 +754,13 @@ var utils = require('./../public/src/utils.js'),
callback = null; callback = null;
} }
RDB.get('reset:' + code + ':uid', function(err, uid) { RDB.hget('reset:uid', code, function(err, uid) {
if (err) { if (err) {
RDB.handle(err); RDB.handle(err);
} }
if (uid !== null) { if (uid !== null) {
RDB.get('reset:' + code + ':expiry', function(err, expiry) { RDB.hget('reset:expiry', code, function(err, expiry) {
if (err) { if (err) {
RDB.handle(err); RDB.handle(err);
} }
@ -802,8 +775,8 @@ var utils = require('./../public/src/utils.js'),
} }
} else { } else {
// Expired, delete from db // Expired, delete from db
RDB.del('reset:' + code + ':uid'); RDB.hdel('reset:uid', code);
RDB.del('reset:' + code + ':expiry'); RDB.hdel('reset:expiry', code);
if (!callback) { if (!callback) {
socket.emit('user:reset.valid', { socket.emit('user:reset.valid', {
valid: false valid: false
@ -829,8 +802,8 @@ var utils = require('./../public/src/utils.js'),
if (uid !== null) { if (uid !== null) {
// Generate a new reset code // Generate a new reset code
var reset_code = utils.generateUUID(); var reset_code = utils.generateUUID();
RDB.set('reset:' + reset_code + ':uid', uid); RDB.hset('reset:uid', reset_code, uid);
RDB.set('reset:' + reset_code + ':expiry', (60 * 60) + new Date() / 1000 | 0); // Active for one hour 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, var reset_link = nconf.get('url') + 'reset/' + reset_code,
reset_email = global.templates['emails/reset'].parse({ reset_email = global.templates['emails/reset'].parse({
@ -879,7 +852,7 @@ var utils = require('./../public/src/utils.js'),
commit: function(socket, code, password) { commit: function(socket, code, password) {
this.validate(socket, code, function(validated) { this.validate(socket, code, function(validated) {
if (validated) { if (validated) {
RDB.get('reset:' + code + ':uid', function(err, uid) { RDB.hget('reset:uid', code, function(err, uid) {
if (err) { if (err) {
RDB.handle(err); RDB.handle(err);
} }
@ -888,8 +861,8 @@ var utils = require('./../public/src/utils.js'),
User.setUserField(uid, 'password', hash); User.setUserField(uid, 'password', hash);
}); });
RDB.del('reset:' + code + ':uid'); RDB.hdel('reset:uid', code);
RDB.del('reset:' + code + ':expiry'); RDB.hdel('reset:expiry', code);
socket.emit('user:reset.commit', { socket.emit('user:reset.commit', {
status: 'ok' status: 'ok'

@ -126,13 +126,6 @@ var express = require('express'),
nconf.set('https', req.secure); 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(); next();
}); });

Loading…
Cancel
Save