Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to query User object for payload UID #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion library.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ plugin.findOrCreateUser = function (userData, callback) {
}
queries.uid = async.apply(db.sortedSetScore, plugin.settings.name + ':uid', userData.id);

if (plugin.settings.useUserObject === 'on')
queries.id = async.apply(db.getObjectField, 'user:' + userData.id, 'uid');

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation should be tabs for this plugin, thanks

async.parallel(queries, function (err, checks) {
if (err) { return callback(err); }

Expand All @@ -241,7 +244,7 @@ plugin.findOrCreateUser = function (userData, callback) {
return user.exists(uid, function (err, exists) {
/* ignore errors, but assume the user doesn't exist */
if (err) {
winston.warn('[session-sharing] Error while testing user existance', err);
winston.warn('[session-sharing] Error checking user existance in `' + plugin.settings.name + ':uid` object:', err);
return next(null, null);
}
if (exists) {
Expand All @@ -253,6 +256,22 @@ plugin.findOrCreateUser = function (userData, callback) {
});
});
}
if (checks.id && !isNaN(parseInt(checks.id, 10))) {
var uid = parseInt(checks.id, 10);
/* check if the user with the given id actually exists */
return user.exists(uid, function (err, exists) {
/* ignore errors, but assume the user doesn't exist */
if (err) {
winston.warn('[session-sharing] Error checking user existance in `User` object:', err);
return next(null, null);
}
if (exists) {
return next(null, uid);
}

return next(null, null);
});
}
if (checks.mergeUid && !isNaN(parseInt(checks.mergeUid, 10))) {
winston.info('[session-sharing] Found user via their email, associating this id (' + userData.id + ') with their NodeBB account');
return db.sortedSetAdd(plugin.settings.name + ':uid', checks.mergeUid, userData.id, function (err) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodebb-plugin-session-sharing",
"version": "4.5.0",
"version": "4.5.1",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert this line please?

"description": "Allows login sessions from your app to persist in NodeBB",
"main": "library.js",
"repository": {
Expand Down
Loading