2015-08-21 23:08:49 +00:00
|
|
|
const providerHash = {
|
|
|
|
facebook: ({ id }) => id,
|
|
|
|
twitter: ({ username }) => username,
|
|
|
|
linkedin({ _json }) {
|
|
|
|
return _json && _json.publicProfileUrl || null;
|
|
|
|
},
|
|
|
|
google: ({ id }) => id
|
|
|
|
};
|
|
|
|
|
|
|
|
export function getUsernameFromProvider(provider, profile) {
|
|
|
|
return typeof providerHash[provider] === 'function' ?
|
|
|
|
providerHash[provider](profile) :
|
|
|
|
null;
|
|
|
|
}
|
|
|
|
|
2015-08-12 19:15:19 +00:00
|
|
|
// using es6 argument destructing
|
|
|
|
export function setProfileFromGithub(
|
|
|
|
user,
|
|
|
|
{
|
|
|
|
profileUrl: githubURL,
|
|
|
|
username
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: githubId,
|
2016-04-15 15:48:02 +00:00
|
|
|
avatar_url: picture,
|
2015-08-12 19:15:19 +00:00
|
|
|
email: githubEmail,
|
2016-04-15 15:48:02 +00:00
|
|
|
created_at: joinedGithubOn,
|
2015-08-12 19:15:19 +00:00
|
|
|
blog: website,
|
|
|
|
location,
|
2016-06-18 17:57:36 +00:00
|
|
|
bio,
|
2015-08-12 19:15:19 +00:00
|
|
|
name
|
|
|
|
}
|
|
|
|
) {
|
2016-04-22 03:35:19 +00:00
|
|
|
return Object.assign(
|
2015-08-12 19:15:19 +00:00
|
|
|
user,
|
|
|
|
{
|
|
|
|
name,
|
2016-04-22 03:35:19 +00:00
|
|
|
email: user.email || githubEmail,
|
2015-08-12 19:15:19 +00:00
|
|
|
username: username.toLowerCase(),
|
|
|
|
location,
|
2016-06-18 17:57:36 +00:00
|
|
|
bio,
|
2015-08-12 19:15:19 +00:00
|
|
|
joinedGithubOn,
|
|
|
|
website,
|
2016-04-22 03:35:19 +00:00
|
|
|
isGithubCool: true,
|
2015-08-12 19:15:19 +00:00
|
|
|
picture,
|
|
|
|
githubId,
|
|
|
|
githubURL,
|
|
|
|
githubEmail,
|
|
|
|
githubProfile: githubURL
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getFirstImageFromProfile(profile) {
|
|
|
|
return profile && profile.photos && profile.photos[0] ?
|
|
|
|
profile.photos[0].value :
|
|
|
|
null;
|
|
|
|
}
|
2015-08-13 02:08:05 +00:00
|
|
|
|
|
|
|
export function getSocialProvider(provider) {
|
|
|
|
return provider.split('-')[0];
|
|
|
|
}
|