pull user bio from github
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
import assign from 'object.assign';
|
||||||
import debugFactory from 'debug';
|
import debugFactory from 'debug';
|
||||||
|
|
||||||
const debug = debugFactory('freecc:models:userIdent');
|
const debug = debugFactory('freecc:models:userIdent');
|
||||||
@ -10,6 +11,39 @@ function getFirstImageFromProfile(profile) {
|
|||||||
null;
|
null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// using es6 argument destructing
|
||||||
|
function setProfileFromGithub(
|
||||||
|
user,
|
||||||
|
{
|
||||||
|
profileUrl: githubURL,
|
||||||
|
username
|
||||||
|
},
|
||||||
|
{
|
||||||
|
location,
|
||||||
|
email: githubEmail,
|
||||||
|
id: githubId,
|
||||||
|
'created_at': joinedGithubOn,
|
||||||
|
blog: website,
|
||||||
|
name
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
return assign(
|
||||||
|
user,
|
||||||
|
{ isGithubCool: true, isMigrationGrandfathered: false },
|
||||||
|
{
|
||||||
|
name,
|
||||||
|
username: username.toLowerCase(),
|
||||||
|
location,
|
||||||
|
joinedGithubOn,
|
||||||
|
website,
|
||||||
|
githubId,
|
||||||
|
githubURL,
|
||||||
|
githubEmail,
|
||||||
|
githubProfile: githubURL
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default function(UserIdent) {
|
export default function(UserIdent) {
|
||||||
UserIdent.observe('before save', function(ctx, next) {
|
UserIdent.observe('before save', function(ctx, next) {
|
||||||
var userIdent = ctx.currentInstance || ctx.instance;
|
var userIdent = ctx.currentInstance || ctx.instance;
|
||||||
@ -25,7 +59,8 @@ export default function(UserIdent) {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
const picture = getFirstImageFromProfile(userIdent.profile);
|
const { profile } = userIdent;
|
||||||
|
const picture = getFirstImageFromProfile(profile);
|
||||||
|
|
||||||
debug('picture', picture, user.picture);
|
debug('picture', picture, user.picture);
|
||||||
// check if picture was found
|
// check if picture was found
|
||||||
@ -41,19 +76,10 @@ export default function(UserIdent) {
|
|||||||
userChanged = true;
|
userChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if user signed in with github
|
// if user signed in with github refresh their info
|
||||||
// and user is not github cool
|
if (userIdent.provider === 'github-login') {
|
||||||
// or username is different from github username
|
|
||||||
// then make them github cool
|
|
||||||
// and set their username from their github profile.
|
|
||||||
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");
|
debug("user isn't github cool or username from github is different");
|
||||||
user.isGithubCool = true;
|
setProfileFromGithub(user, profile, profile._json);
|
||||||
user.username = userIdent.profile.username.toLowerCase();
|
|
||||||
userChanged = true;
|
userChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,18 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
|
"githubId": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"githubURL": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"githubEmail": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"joinedGithubOn": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
"isMigrationGrandfathered": {
|
"isMigrationGrandfathered": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
|
Reference in New Issue
Block a user