revamped social auth code so that accounts are merged if they share a common email

also updated auth code so that fbid gplusid and twid are saved in the hash instead of as simple key->value
v1.18.x
Julian Lam 12 years ago
parent 55cb790d3c
commit 33f8ee57bf

@ -196,8 +196,8 @@ var config = require('../config.js'),
callback(err); callback(err);
} else { } else {
// Save twitter-specific information to the user // Save twitter-specific information to the user
RDB.set('uid:' + uid + ':twid', twid); User.setUserField(uid, 'twid', twid);
RDB.set('twid:' + twid + ':uid', uid); RDB.hset('twid:uid', twid, uid);
callback(null, { callback(null, {
uid: uid uid: uid
}); });
@ -216,17 +216,23 @@ var config = require('../config.js'),
}); });
} else { } else {
// New User // New User
User.create(handle, null, email, function(err, uid) { var success = function(uid) {
if (err !== null) { // Save google-specific information to the user
callback(err); User.setUserField(uid, 'gplusid', gplusid);
} else { RDB.hset('gplusid:uid', gplusid, uid);
// Save twitter-specific information to the user callback(null, {
RDB.set('uid:' + uid + ':gplusid', gplusid); uid: uid
RDB.set('gplusid:' + gplusid + ':uid', uid); });
callback(null, { }
uid: uid
User.get_uid_by_email(email, function(uid) {
if (!uid) {
User.create(handle, null, email, function(err, uid) {
if (err !== null) {
callback(err);
} else success(uid);
}); });
} } else success(uid); // Existing account -- merge
}); });
} }
}); });
@ -241,17 +247,23 @@ var config = require('../config.js'),
}); });
} else { } else {
// New User // New User
User.create(name, null, email, function(err, uid) { var success = function(uid) {
if (err !== null) { // Save facebook-specific information to the user
callback(err); User.setUserField(uid, 'fbid', fbid);
} else { RDB.hset('fbid:uid', fbid, uid);
// Save twitter-specific information to the user
RDB.set('uid:' + uid + ':fbid', fbid);
RDB.set('fbid:' + fbid + ':uid', uid);
callback(null, { callback(null, {
uid: uid uid: uid
}); });
} }
User.get_uid_by_email(email, function(uid) {
if (!uid) {
User.create(name, null, email, function(err, uid) {
if (err !== null) {
callback(err);
} else success(uid);
});
} else success(uid); // Existing account -- merge
}); });
} }
}); });
@ -493,21 +505,21 @@ var config = require('../config.js'),
}; };
User.get_uid_by_twitter_id = function(twid, callback) { User.get_uid_by_twitter_id = function(twid, callback) {
RDB.get('twid:' + twid + ':uid', function(err, uid) { RDB.hget('twid:uid', twid, function(err, uid) {
RDB.handle(err); RDB.handle(err);
callback(uid); callback(uid);
}); });
} }
User.get_uid_by_google_id = function(gplusid, callback) { User.get_uid_by_google_id = function(gplusid, callback) {
RDB.get('gplusid:' + gplusid + ':uid', function(err, uid) { RDB.hget('gplusid:uid', gplusid, function(err, uid) {
RDB.handle(err); RDB.handle(err);
callback(uid); callback(uid);
}); });
} }
User.get_uid_by_fbid = function(fbid, callback) { User.get_uid_by_fbid = function(fbid, callback) {
RDB.get('fbid:' + fbid + ':uid', function(err, uid) { RDB.hget('fbid:uid', fbid, function(err, uid) {
RDB.handle(err); RDB.handle(err);
callback(uid); callback(uid);
}); });

Loading…
Cancel
Save