Add OAuth.deleteUserData method

Removes the user's oAuthId-to-uid mapping from Redis upon user deletion.
This fixes an issue where OAuth services could not link to a user if a
user account was deleted and then re-created.
This commit is contained in:
dhingey 2014-07-09 00:32:44 -07:00
parent f8306923de
commit 5df4097aa0
2 changed files with 23 additions and 0 deletions

View File

@ -232,5 +232,27 @@
});
};
OAuth.deleteUserData = function(uid) {
db.getObject('oAuthid:uid', function(err, oAuthData) {
if (err) {
winston.error('Could not fetch OAuthId data from Redis. Error: ' + 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);
}
});
}
});
};
module.exports = OAuth;
}(module));

View File

@ -6,6 +6,7 @@
"library": "./library.js",
"hooks": [
{ "hook": "action:app.load", "method": "init" },
{ "hook": "action:user.delete", "method": "deleteUserData" },
{ "hook": "filter:auth.init", "method": "getStrategy" },
{ "hook": "filter:admin.header.build", "method": "addMenuItem" }
],