fix profile linking
This commit is contained in:
@ -4,12 +4,13 @@ import debugFactory from 'debug';
|
|||||||
import {
|
import {
|
||||||
setProfileFromGithub,
|
setProfileFromGithub,
|
||||||
getFirstImageFromProfile,
|
getFirstImageFromProfile,
|
||||||
|
getUsernameFromProvider,
|
||||||
getSocialProvider
|
getSocialProvider
|
||||||
} from '../../server/utils/auth';
|
} from '../../server/utils/auth';
|
||||||
|
|
||||||
const debug = debugFactory('freecc:models:userIdent');
|
|
||||||
|
|
||||||
const { defaultProfileImage } = require('../utils/constantStrings.json');
|
const { defaultProfileImage } = require('../utils/constantStrings.json');
|
||||||
|
const githubRegex = (/github/i);
|
||||||
|
const debug = debugFactory('freecc:models:userIdent');
|
||||||
|
|
||||||
function createAccessToken(user, ttl, cb) {
|
function createAccessToken(user, ttl, cb) {
|
||||||
if (arguments.length === 2 && typeof ttl === 'function') {
|
if (arguments.length === 2 && typeof ttl === 'function') {
|
||||||
@ -158,14 +159,13 @@ export default function(UserIdent) {
|
|||||||
userChanged = true;
|
userChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(/github/).test(provider) && profile) {
|
if (!githubRegex.test(provider) && profile) {
|
||||||
debug('setting social', provider, (/github/g).test(provider));
|
user[provider] = getUsernameFromProvider(provider, profile);
|
||||||
debug('profile username', profile.username);
|
userChanged = true;
|
||||||
user[provider] = profile.username;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if user signed in with github refresh their info
|
// if user signed in with github refresh their info
|
||||||
if (/github/.test(provider) && profile && profile._json) {
|
if (githubRegex.test(provider) && profile && profile._json) {
|
||||||
debug("user isn't github cool or username from github is different");
|
debug("user isn't github cool or username from github is different");
|
||||||
setProfileFromGithub(user, profile, profile._json);
|
setProfileFromGithub(user, profile, profile._json);
|
||||||
userChanged = true;
|
userChanged = true;
|
||||||
|
@ -54,7 +54,7 @@ export default function({ models }) {
|
|||||||
}
|
}
|
||||||
identity.credentials = credentials;
|
identity.credentials = credentials;
|
||||||
return observeQuery(identity, 'updateAttributes', {
|
return observeQuery(identity, 'updateAttributes', {
|
||||||
profile: getSocialProvider(provider),
|
profile,
|
||||||
credentials,
|
credentials,
|
||||||
modified
|
modified
|
||||||
});
|
});
|
||||||
|
@ -194,11 +194,11 @@ module.exports = function(app) {
|
|||||||
isMigrationGrandfathered: user.isMigrationGrandfathered,
|
isMigrationGrandfathered: user.isMigrationGrandfathered,
|
||||||
isGithubCool: user.isGithubCool,
|
isGithubCool: user.isGithubCool,
|
||||||
location: user.location,
|
location: user.location,
|
||||||
githubProfile: user.github,
|
github: user.githubURL,
|
||||||
linkedinProfile: user.linkedin,
|
linkedin: user.linkedin,
|
||||||
googleProfile: user.google,
|
google: user.google,
|
||||||
facebookProfile: user.facebook,
|
facebook: user.facebook,
|
||||||
twitterHandle: user.twitter,
|
twitter: user.twitter,
|
||||||
picture: user.picture,
|
picture: user.picture,
|
||||||
progressTimestamps: user.progressTimestamps,
|
progressTimestamps: user.progressTimestamps,
|
||||||
calender: data,
|
calender: data,
|
||||||
|
@ -12,6 +12,7 @@ var uuid = require('node-uuid'),
|
|||||||
|
|
||||||
var setProfileFromGithub = require('./utils/auth').setProfileFromGithub;
|
var setProfileFromGithub = require('./utils/auth').setProfileFromGithub;
|
||||||
var getSocialProvider = require('./utils/auth').getSocialProvider;
|
var getSocialProvider = require('./utils/auth').getSocialProvider;
|
||||||
|
var getUsernameFromProvider = require('./utils/auth').getUsernameFromProvider;
|
||||||
var generateKey =
|
var generateKey =
|
||||||
require('loopback-component-passport/lib/models/utils').generateKey;
|
require('loopback-component-passport/lib/models/utils').generateKey;
|
||||||
|
|
||||||
@ -69,7 +70,10 @@ var passportOptions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(/github/).test(provider)) {
|
if (!(/github/).test(provider)) {
|
||||||
userObj[getSocialProvider(provider)] = profile.username;
|
userObj[getSocialProvider(provider)] = getUsernameFromProvider(
|
||||||
|
getSocialProvider(provider),
|
||||||
|
profile
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/github/.test(provider)) {
|
if (/github/.test(provider)) {
|
||||||
|
@ -1,5 +1,21 @@
|
|||||||
import assign from 'object.assign';
|
import assign from 'object.assign';
|
||||||
|
|
||||||
|
const providerHash = {
|
||||||
|
facebook: ({ id }) => id,
|
||||||
|
twitter: ({ username }) => username,
|
||||||
|
linkedin({ _json }) {
|
||||||
|
return _json && _json.publicProfileUrl || null;
|
||||||
|
},
|
||||||
|
google: ({ id }) => id
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getUsernameFromProvider(provider, profile) {
|
||||||
|
console.log(profile);
|
||||||
|
return typeof providerHash[provider] === 'function' ?
|
||||||
|
providerHash[provider](profile) :
|
||||||
|
null;
|
||||||
|
}
|
||||||
|
|
||||||
// using es6 argument destructing
|
// using es6 argument destructing
|
||||||
export function setProfileFromGithub(
|
export function setProfileFromGithub(
|
||||||
user,
|
user,
|
||||||
|
@ -24,15 +24,15 @@ block content
|
|||||||
img.img-center.img-responsive.public-profile-img(src='https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png')
|
img.img-center.img-responsive.public-profile-img(src='https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png')
|
||||||
h1.text-center.negative-5.profile-social-icons
|
h1.text-center.negative-5.profile-social-icons
|
||||||
if (twitter)
|
if (twitter)
|
||||||
a.fa.fa-twitter-square.text-primary(title="@#{username}'s Twitter Profile", href=twitter, target='_blank')
|
a.fa.fa-twitter-square.text-primary(title="@#{username}'s Twitter Profile", href='https://twitter.com/' + twitter, target='_blank')
|
||||||
if (github)
|
if (github)
|
||||||
a.fa.fa-github-square.text-primary(title="@#{username}'s GitHub Profile", href=github, target='_blank')
|
a.fa.fa-github-square.text-primary(title="@#{username}'s GitHub Profile", href=github, target='_blank')
|
||||||
if (linkedin)
|
if (linkedin)
|
||||||
a.fa.fa-linkedin-square.text-primary(title="@#{username}'s LinkedIn Profile", href=linkedin, target='_blank')
|
a.fa.fa-linkedin-square.text-primary(title="@#{username}'s LinkedIn Profile", href=linkedin, target='_blank')
|
||||||
if (facebook)
|
if (facebook)
|
||||||
a.fa.fa-facebook-square.text-primary(title="@#{username}'s Facebook Profile", href=facebook, target='_blank')
|
a.fa.fa-facebook-square.text-primary(title="@#{username}'s Facebook Profile", href='https://facebook.com/' + facebook, target='_blank')
|
||||||
if (google)
|
if (google)
|
||||||
a.fa.fa-google-square.text-primary(title="@#{username}'s Google Profile", href=google, target='_blank')
|
a.fa.fa-google-plus-square.text-primary(title="@#{username}'s Google Profile", href='https://plus.google.com/' + google, target='_blank')
|
||||||
.visible-md.visible-lg
|
.visible-md.visible-lg
|
||||||
.col-xs-12.col-sm-12.col-md-4.text-justify
|
.col-xs-12.col-sm-12.col-md-4.text-justify
|
||||||
h1.flat-top.wrappable= name
|
h1.flat-top.wrappable= name
|
||||||
|
Reference in New Issue
Block a user