@ -132,52 +132,54 @@ export default function(UserIdent) {
|
||||
if (!userIdent) {
|
||||
debug('no user identity instance found');
|
||||
return next();
|
||||
}
|
||||
userIdent.user(function(err, user) {
|
||||
let userChanged = false;
|
||||
if (err) { return next(err); }
|
||||
if (!user) {
|
||||
debug('no user attached to identity!');
|
||||
return next();
|
||||
}
|
||||
userIdent.user(function(err, user) {
|
||||
let userChanged = false;
|
||||
if (err) { return next(err); }
|
||||
if (!user) {
|
||||
debug('no user attached to identity!');
|
||||
return next();
|
||||
}
|
||||
|
||||
const { profile, provider } = userIdent;
|
||||
const picture = getFirstImageFromProfile(profile);
|
||||
const { profile, provider } = userIdent;
|
||||
const picture = getFirstImageFromProfile(profile);
|
||||
|
||||
debug('picture', picture, user.picture);
|
||||
// check if picture was found
|
||||
// check if user has no picture
|
||||
// check if user has default picture
|
||||
// set user.picture from oauth provider
|
||||
if (
|
||||
picture &&
|
||||
(!user.picture || user.picture === defaultProfileImage)
|
||||
) {
|
||||
debug('setting user picture');
|
||||
user.picture = picture;
|
||||
userChanged = true;
|
||||
}
|
||||
debug('picture', picture, user.picture);
|
||||
// check if picture was found
|
||||
// check if user has no picture
|
||||
// check if user has default picture
|
||||
// set user.picture from oauth provider
|
||||
if (
|
||||
picture &&
|
||||
(!user.picture || user.picture === defaultProfileImage)
|
||||
) {
|
||||
debug('setting user picture');
|
||||
user.picture = picture;
|
||||
userChanged = true;
|
||||
}
|
||||
|
||||
if (!(/github/).test(provider)) {
|
||||
user[getSocialProvider(provider)] = profile.username;
|
||||
}
|
||||
if (!(/github/).test(provider)) {
|
||||
debug('setting social', provider, (/github/g).test(provider));
|
||||
debug('profile username', profile.username);
|
||||
user[provider] = profile.username;
|
||||
}
|
||||
|
||||
// if user signed in with github refresh their info
|
||||
if (/github/.test(provider)) {
|
||||
debug("user isn't github cool or username from github is different");
|
||||
setProfileFromGithub(user, profile, profile._json);
|
||||
userChanged = true;
|
||||
}
|
||||
// if user signed in with github refresh their info
|
||||
if (/github/.test(provider)) {
|
||||
debug("user isn't github cool or username from github is different");
|
||||
setProfileFromGithub(user, profile, profile._json);
|
||||
userChanged = true;
|
||||
}
|
||||
|
||||
|
||||
if (userChanged) {
|
||||
return user.save(function(err) {
|
||||
if (err) { return next(err); }
|
||||
next();
|
||||
});
|
||||
}
|
||||
debug('exiting after user identity before save');
|
||||
next();
|
||||
if (userChanged) {
|
||||
return user.save(function(err) {
|
||||
if (err) { return next(err); }
|
||||
next();
|
||||
});
|
||||
}
|
||||
debug('exiting after user identity before save');
|
||||
next();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user