fix profile linking
This commit is contained in:
@ -4,12 +4,13 @@ import debugFactory from 'debug';
|
||||
import {
|
||||
setProfileFromGithub,
|
||||
getFirstImageFromProfile,
|
||||
getUsernameFromProvider,
|
||||
getSocialProvider
|
||||
} from '../../server/utils/auth';
|
||||
|
||||
const debug = debugFactory('freecc:models:userIdent');
|
||||
|
||||
const { defaultProfileImage } = require('../utils/constantStrings.json');
|
||||
const githubRegex = (/github/i);
|
||||
const debug = debugFactory('freecc:models:userIdent');
|
||||
|
||||
function createAccessToken(user, ttl, cb) {
|
||||
if (arguments.length === 2 && typeof ttl === 'function') {
|
||||
@ -158,14 +159,13 @@ export default function(UserIdent) {
|
||||
userChanged = true;
|
||||
}
|
||||
|
||||
if (!(/github/).test(provider) && profile) {
|
||||
debug('setting social', provider, (/github/g).test(provider));
|
||||
debug('profile username', profile.username);
|
||||
user[provider] = profile.username;
|
||||
if (!githubRegex.test(provider) && profile) {
|
||||
user[provider] = getUsernameFromProvider(provider, profile);
|
||||
userChanged = true;
|
||||
}
|
||||
|
||||
// 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");
|
||||
setProfileFromGithub(user, profile, profile._json);
|
||||
userChanged = true;
|
||||
|
@ -54,7 +54,7 @@ export default function({ models }) {
|
||||
}
|
||||
identity.credentials = credentials;
|
||||
return observeQuery(identity, 'updateAttributes', {
|
||||
profile: getSocialProvider(provider),
|
||||
profile,
|
||||
credentials,
|
||||
modified
|
||||
});
|
||||
|
@ -194,11 +194,11 @@ module.exports = function(app) {
|
||||
isMigrationGrandfathered: user.isMigrationGrandfathered,
|
||||
isGithubCool: user.isGithubCool,
|
||||
location: user.location,
|
||||
githubProfile: user.github,
|
||||
linkedinProfile: user.linkedin,
|
||||
googleProfile: user.google,
|
||||
facebookProfile: user.facebook,
|
||||
twitterHandle: user.twitter,
|
||||
github: user.githubURL,
|
||||
linkedin: user.linkedin,
|
||||
google: user.google,
|
||||
facebook: user.facebook,
|
||||
twitter: user.twitter,
|
||||
picture: user.picture,
|
||||
progressTimestamps: user.progressTimestamps,
|
||||
calender: data,
|
||||
|
@ -12,6 +12,7 @@ var uuid = require('node-uuid'),
|
||||
|
||||
var setProfileFromGithub = require('./utils/auth').setProfileFromGithub;
|
||||
var getSocialProvider = require('./utils/auth').getSocialProvider;
|
||||
var getUsernameFromProvider = require('./utils/auth').getUsernameFromProvider;
|
||||
var generateKey =
|
||||
require('loopback-component-passport/lib/models/utils').generateKey;
|
||||
|
||||
@ -69,7 +70,10 @@ var passportOptions = {
|
||||
}
|
||||
|
||||
if (!(/github/).test(provider)) {
|
||||
userObj[getSocialProvider(provider)] = profile.username;
|
||||
userObj[getSocialProvider(provider)] = getUsernameFromProvider(
|
||||
getSocialProvider(provider),
|
||||
profile
|
||||
);
|
||||
}
|
||||
|
||||
if (/github/.test(provider)) {
|
||||
|
@ -1,5 +1,21 @@
|
||||
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
|
||||
export function setProfileFromGithub(
|
||||
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')
|
||||
h1.text-center.negative-5.profile-social-icons
|
||||
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)
|
||||
a.fa.fa-github-square.text-primary(title="@#{username}'s GitHub Profile", href=github, target='_blank')
|
||||
if (linkedin)
|
||||
a.fa.fa-linkedin-square.text-primary(title="@#{username}'s LinkedIn Profile", href=linkedin, target='_blank')
|
||||
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)
|
||||
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
|
||||
.col-xs-12.col-sm-12.col-md-4.text-justify
|
||||
h1.flat-top.wrappable= name
|
||||
|
Reference in New Issue
Block a user