From d752e5b4874cbf6af4e63fb562782336a13ef1bb Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Tue, 4 Aug 2015 15:09:42 -0700 Subject: [PATCH] on login double check that github username if different, assign user to new name --- common/models/User-Identity.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/common/models/User-Identity.js b/common/models/User-Identity.js index 781ea7d0ac..3df7f01400 100644 --- a/common/models/User-Identity.js +++ b/common/models/User-Identity.js @@ -41,20 +41,23 @@ export default function(UserIdent) { userChanged = true; } - // if user is not github cool - // and user signed in with github + // if user signed in with github + // and user is not github cool + // or username is different from github username // then make them github cool // and set their username from their github profile. - if (!user.isGithubCool && userIdent.provider === 'github-login') { - debug(` - user isn't github cool yet but signed in with github - lets make them cool! - `); + if ( + userIdent.provider === 'github-login' && + (!user.isGithubCool || + user.username !== userIdent.provider.username.toLowerCase()) + ) { + debug("user isn't github cool or username from github is different"); user.isGithubCool = true; user.username = userIdent.profile.username.toLowerCase(); userChanged = true; } + if (userChanged) { return user.save(function(err) { if (err) { return next(err); }