Skip to content

Commit

Permalink
Fix new registration and changing default authentication method for G…
Browse files Browse the repository at this point in the history
…oogle using OAuth.
  • Loading branch information
sizzlemctwizzle committed Feb 5, 2015
1 parent 3af7fad commit b49b2cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions libs/passportVerify.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ exports.verify = function (aId, aStrategy, aUsername, aLoggedIn, aDone) {
var shasum = crypto.createHash('sha256');
var digest = null;
var query = {};
var aIds = [];
var ids = [];

if (aId instanceof Array) {
aIds = aId.map(function (aId) {
ids = aId.map(function (aId) {
var shasum = crypto.createHash('sha256');
shasum.update(String(aId));
return shasum.digest('hex');
});
query.auths = { '$in': aIds };
query.auths = { '$in': ids };
} else if (aStrategy === 'github') {
// We only keep plaintext ids for GH since that's all we need
digest = aId;
Expand All @@ -42,9 +42,19 @@ exports.verify = function (aId, aStrategy, aUsername, aLoggedIn, aDone) {

findDeadorAlive(User, query, true,
function (aAlive, aUser, aRemoved) {
var pos = aUser ? aUser.auths.indexOf(digest || aIds[0]) : -1;
var pos = aUser ? aUser.auths.indexOf(digest) : -1;
var opendIdPos = -1;

This comment has been minimized.

Copy link
@Martii

Martii Feb 5, 2015

Member

This isn't blocking but did you mean to type openIdIdPos for the identifier? Took me a bit to figure out what it meant... from a general naming perspective.

This comment has been minimized.

Copy link
@sizzlemctwizzle

sizzlemctwizzle via email Feb 5, 2015

Author Member
if (aRemoved) { aDone(null, false, 'user was removed'); }

// Set up for OpenId to OAuth Migration
if (!digest && ids.length > 0) {
digest = ids[1];
if (aUser) {
pos = aUser.auths.indexOf(digest);
opendIdPos = aUser.auths.indexOf(ids[0]);
}
}

if (!aUser) {
User.findOne({ 'name': aUsername }, function (aErr, aUser) {
if (aUser && aLoggedIn) {
Expand Down Expand Up @@ -82,9 +92,9 @@ exports.verify = function (aId, aStrategy, aUsername, aLoggedIn, aDone) {
aUser.save(function (aErr, aUser) {
return aDone(aErr, aUser);
});
} else if (aIds.length > 0 && pos > -1) {
} else if (opendIdPos > 0) {
// Migrate from OpenID to OAuth
aUser.auths[pos] = aIds[1];
aUser.auths[opendIdPos] = digest;
aUser.save(function (aErr, aUser) {
return aDone(aErr, aUser);
});
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"github": "0.2.3",
"highlight.js": "8.4.0",
"jquery": "2.1.3",
"jwt-simple": "0.2.0",
"less-middleware": "1.0.4",
"marked": "0.3.3",
"method-override": "2.3.1",
Expand Down Expand Up @@ -52,8 +53,7 @@
"select2": "3.5.2-browserify",
"select2-bootstrap-css": "1.4.6",
"serve-favicon": "2.2.0",
"underscore": "1.7.0",
"jwt-simple": "0.2.0"
"underscore": "1.7.0"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit b49b2cb

Please sign in to comment.