Skip to content
Permalink
Browse files

Closes #202 - if user does not authorize email scope, email will not …

…be mapped. Username will be generated from first initial of first name and last name.

.jshint latedef set to nofunc.
  • Loading branch information...
rhutchison committed Aug 23, 2015
1 parent b1f814e commit 27d2818834e45a1fa7c079a15bce59936f8ad3fd
Showing with 15 additions and 2 deletions.
  1. +1 −1 .jshintrc
  2. +14 −1 modules/users/server/config/strategies/facebook.js
@@ -7,7 +7,7 @@
"bitwise": false, // Prohibit bitwise operators (&, |, ^, etc.).
"curly": false, // Require {} for every new block or scope.
"eqeqeq": true, // Require triple equals i.e. `===`.
"latedef": true, // Prohibit variable use before definition.
"latedef": "nofunc", // Prohibit variable use before definition.
"noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"undef": true, // Require all non-global variables be declared before they are used.
"unused": false, // Warn unused variables.
@@ -27,7 +27,8 @@ module.exports = function (config) {
firstName: profile.name.givenName,
lastName: profile.name.familyName,
displayName: profile.displayName,
email: profile.emails[0].value,
email: profile.emails ? profile.emails[0].value : undefined,
username: profile.username || generateUsername(profile),
profileImageURL: (profile.id) ? '//graph.facebook.com/' + profile.id + '/picture?type=large' : undefined,
provider: 'facebook',
providerIdentifierField: 'id',
@@ -36,6 +37,18 @@ module.exports = function (config) {

// Save the user OAuth profile
users.saveOAuthUserProfile(req, providerUserProfile, done);

function generateUsername(profile) {
var username = '';

if (profile.emails) {
username = profile.emails[0].value.split('@')[0];
} else if (profile.name) {
username = profile.name.givenName[0] + profile.name.familyName;
}

return username.toLowerCase() || undefined;
}
}
));
};

0 comments on commit 27d2818

Please sign in to comment.
You can’t perform that action at this time.