Skip to content

Commit b49b2cb

Browse files
Fix new registration and changing default authentication method for Google using OAuth.
1 parent 3af7fad commit b49b2cb

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

libs/passportVerify.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ exports.verify = function (aId, aStrategy, aUsername, aLoggedIn, aDone) {
1717
var shasum = crypto.createHash('sha256');
1818
var digest = null;
1919
var query = {};
20-
var aIds = [];
20+
var ids = [];
2121

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

4343
findDeadorAlive(User, query, true,
4444
function (aAlive, aUser, aRemoved) {
45-
var pos = aUser ? aUser.auths.indexOf(digest || aIds[0]) : -1;
45+
var pos = aUser ? aUser.auths.indexOf(digest) : -1;
46+
var opendIdPos = -1;
4647
if (aRemoved) { aDone(null, false, 'user was removed'); }
4748

49+
// Set up for OpenId to OAuth Migration
50+
if (!digest && ids.length > 0) {
51+
digest = ids[1];
52+
if (aUser) {
53+
pos = aUser.auths.indexOf(digest);
54+
opendIdPos = aUser.auths.indexOf(ids[0]);
55+
}
56+
}
57+
4858
if (!aUser) {
4959
User.findOne({ 'name': aUsername }, function (aErr, aUser) {
5060
if (aUser && aLoggedIn) {
@@ -82,9 +92,9 @@ exports.verify = function (aId, aStrategy, aUsername, aLoggedIn, aDone) {
8292
aUser.save(function (aErr, aUser) {
8393
return aDone(aErr, aUser);
8494
});
85-
} else if (aIds.length > 0 && pos > -1) {
95+
} else if (opendIdPos > 0) {
8696
// Migrate from OpenID to OAuth
87-
aUser.auths[pos] = aIds[1];
97+
aUser.auths[opendIdPos] = digest;
8898
aUser.save(function (aErr, aUser) {
8999
return aDone(aErr, aUser);
90100
});

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"github": "0.2.3",
2222
"highlight.js": "8.4.0",
2323
"jquery": "2.1.3",
24+
"jwt-simple": "0.2.0",
2425
"less-middleware": "1.0.4",
2526
"marked": "0.3.3",
2627
"method-override": "2.3.1",
@@ -52,8 +53,7 @@
5253
"select2": "3.5.2-browserify",
5354
"select2-bootstrap-css": "1.4.6",
5455
"serve-favicon": "2.2.0",
55-
"underscore": "1.7.0",
56-
"jwt-simple": "0.2.0"
56+
"underscore": "1.7.0"
5757
},
5858
"repository": {
5959
"type": "git",

0 commit comments

Comments
 (0)