Fix OAuth.deleteUserData to use filter hook
The action:user.create hook in NodeBB was recently changed to filter.user:create, which allows the OAuth.deleteUserData method to remove OAuth data for the user more directly.
This commit is contained in:
parent
5df4097aa0
commit
327a84f222
28
library.js
28
library.js
@ -9,6 +9,7 @@
|
|||||||
path = module.parent.require('path'),
|
path = module.parent.require('path'),
|
||||||
nconf = module.parent.require('nconf'),
|
nconf = module.parent.require('nconf'),
|
||||||
winston = module.parent.require('winston'),
|
winston = module.parent.require('winston'),
|
||||||
|
async = module.parent.require('async'),
|
||||||
passportOAuth;
|
passportOAuth;
|
||||||
|
|
||||||
var constants = Object.freeze({
|
var constants = Object.freeze({
|
||||||
@ -232,25 +233,18 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
OAuth.deleteUserData = function(uid) {
|
OAuth.deleteUserData = function(uid, callback) {
|
||||||
db.getObject('oAuthid:uid', function(err, oAuthData) {
|
async.waterfall([
|
||||||
|
async.apply(User.getUserField, uid, 'oAuthid'),
|
||||||
|
function(oAuthIdToDelete, next) {
|
||||||
|
db.deleteObjectField('oAuthid:uid', oAuthIdToDelete, next);
|
||||||
|
}
|
||||||
|
], function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
winston.error('Could not fetch OAuthId data from Redis. Error: ' + err);
|
winston.error('Could not remove OAuthId data for uid ' + uid + '. Error: ' + err);
|
||||||
}
|
return callback(err);
|
||||||
var oAuthIdToDelete;
|
|
||||||
for (var oAuthId in oAuthData) {
|
|
||||||
if (oAuthData.hasOwnProperty(oAuthId) && oAuthData[oAuthId] === uid) {
|
|
||||||
oAuthIdToDelete = oAuthId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (typeof oAuthIdToDelete !== 'undefined') {
|
|
||||||
// Delete the oAuthId-to-uid mapping for the user
|
|
||||||
db.deleteObjectField('oAuthid:uid', oAuthIdToDelete, function(err, numDeletes) {
|
|
||||||
if (err) {
|
|
||||||
winston.error('Could not remove OAuthId data for uid ' + uid + '. Error: ' + err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
"library": "./library.js",
|
"library": "./library.js",
|
||||||
"hooks": [
|
"hooks": [
|
||||||
{ "hook": "action:app.load", "method": "init" },
|
{ "hook": "action:app.load", "method": "init" },
|
||||||
{ "hook": "action:user.delete", "method": "deleteUserData" },
|
{ "hook": "filter:user.delete", "method": "deleteUserData" },
|
||||||
{ "hook": "filter:auth.init", "method": "getStrategy" },
|
{ "hook": "filter:auth.init", "method": "getStrategy" },
|
||||||
{ "hook": "filter:admin.header.build", "method": "addMenuItem" }
|
{ "hook": "filter:admin.header.build", "method": "addMenuItem" }
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user