mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-21 07:50:37 +01:00
closes #4054
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async'),
|
var async = require('async');
|
||||||
|
|
||||||
user = require('../../user'),
|
var db = require('../../database');
|
||||||
db = require('../../database');
|
var user = require('../../user');
|
||||||
|
|
||||||
var sessionController = {};
|
var sessionController = {};
|
||||||
|
|
||||||
@@ -15,21 +15,30 @@ sessionController.revoke = function(req, res, next) {
|
|||||||
var _id;
|
var _id;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(db.getObjectField, 'uid:' + req.uid + ':sessionUUID:sessionId', req.params.uuid),
|
function (next) {
|
||||||
function(sessionId, next) {
|
db.getSortedSetRange('uid:' + req.uid + ':sessions', 0, -1, next);
|
||||||
if (!sessionId) {
|
},
|
||||||
|
function (sids, done) {
|
||||||
|
async.eachSeries(sids, function(sid, next) {
|
||||||
|
db.sessionStore.get(sid, function(err, sessionObj) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
if (sessionObj && sessionObj.meta && sessionObj.meta.uuid === req.params.uuid) {
|
||||||
|
_id = sid;
|
||||||
|
done();
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
if (!_id) {
|
||||||
return next(new Error('[[error:no-session-found]]'));
|
return next(new Error('[[error:no-session-found]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
_id = sessionId;
|
user.auth.revokeSession(_id, req.uid, next);
|
||||||
db.isSortedSetMember('uid:' + req.uid + ':sessions', sessionId, next)
|
|
||||||
},
|
|
||||||
function(isMember, next) {
|
|
||||||
if (isMember) {
|
|
||||||
user.auth.revokeSession(_id, req.uid, next);
|
|
||||||
} else {
|
|
||||||
next(new Error('[[error:no-session-found]]'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
], function(err) {
|
], function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -71,11 +71,11 @@ module.exports = function(User) {
|
|||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(db.getSortedSetRange, 'uid:' + uid + ':sessions', 0, -1),
|
async.apply(db.getSortedSetRange, 'uid:' + uid + ':sessions', 0, -1),
|
||||||
function(sids, next) {
|
function (sids, next) {
|
||||||
_sids = sids;
|
_sids = sids;
|
||||||
async.map(sids, db.sessionStore.get.bind(db.sessionStore), next);
|
async.map(sids, db.sessionStore.get.bind(db.sessionStore), next);
|
||||||
},
|
},
|
||||||
function(sessions, next) {
|
function (sessions, next) {
|
||||||
sessions.forEach(function(sessionObj, idx) {
|
sessions.forEach(function(sessionObj, idx) {
|
||||||
if (sessionObj && sessionObj.meta) {
|
if (sessionObj && sessionObj.meta) {
|
||||||
sessionObj.meta.current = curSessionId === _sids[idx];
|
sessionObj.meta.current = curSessionId === _sids[idx];
|
||||||
@@ -87,16 +87,16 @@ module.exports = function(User) {
|
|||||||
expired;
|
expired;
|
||||||
|
|
||||||
sessions = sessions.filter(function(sessionObj, idx) {
|
sessions = sessions.filter(function(sessionObj, idx) {
|
||||||
expired = !sessionObj || !sessionObj.hasOwnProperty('passport')
|
expired = !sessionObj || !sessionObj.hasOwnProperty('passport') ||
|
||||||
|| !sessionObj.passport.hasOwnProperty('user')
|
!sessionObj.passport.hasOwnProperty('user') ||
|
||||||
|| parseInt(sessionObj.passport.user, 10) !== parseInt(uid, 10);
|
parseInt(sessionObj.passport.user, 10) !== parseInt(uid, 10);
|
||||||
|
|
||||||
if (expired) {
|
if (expired) {
|
||||||
expiredSids.push(_sids[idx]);
|
expiredSids.push(_sids[idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return !expired;
|
return !expired;
|
||||||
}, [])
|
});
|
||||||
|
|
||||||
async.each(expiredSids, function(sid, next) {
|
async.each(expiredSids, function(sid, next) {
|
||||||
User.auth.revokeSession(sid, uid, next);
|
User.auth.revokeSession(sid, uid, next);
|
||||||
@@ -104,7 +104,7 @@ module.exports = function(User) {
|
|||||||
next(null, sessions);
|
next(null, sessions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
], function(err, sessions) {
|
], function (err, sessions) {
|
||||||
callback(err, sessions ? sessions.map(function(sessObj) {
|
callback(err, sessions ? sessions.map(function(sessObj) {
|
||||||
sessObj.meta.datetimeISO = new Date(sessObj.meta.datetime).toISOString();
|
sessObj.meta.datetimeISO = new Date(sessObj.meta.datetime).toISOString();
|
||||||
return sessObj.meta;
|
return sessObj.meta;
|
||||||
|
|||||||
Reference in New Issue
Block a user