From 27d2818834e45a1fa7c079a15bce59936f8ad3fd Mon Sep 17 00:00:00 2001 From: Ryan Hutchison Date: Sun, 23 Aug 2015 00:32:36 -0400 Subject: [PATCH 1/2] 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. --- .jshintrc | 2 +- .../users/server/config/strategies/facebook.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.jshintrc b/.jshintrc index 7b70ef4901..2466369095 100644 --- a/.jshintrc +++ b/.jshintrc @@ -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. diff --git a/modules/users/server/config/strategies/facebook.js b/modules/users/server/config/strategies/facebook.js index 0f53a6a767..2f2180b8d7 100644 --- a/modules/users/server/config/strategies/facebook.js +++ b/modules/users/server/config/strategies/facebook.js @@ -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; + } } )); }; From b2495120c3268ebc20e9cecfa50995d27e47fb0e Mon Sep 17 00:00:00 2001 From: Ryan Hutchison Date: Sun, 23 Aug 2015 00:48:17 -0400 Subject: [PATCH 2/2] use pushstate, fall back to window.location.hash. current implementation does double redirect due to '#!' --- modules/core/client/app/init.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/core/client/app/init.js b/modules/core/client/app/init.js index 33470bae9a..1ad7bb3959 100644 --- a/modules/core/client/app/init.js +++ b/modules/core/client/app/init.js @@ -46,8 +46,20 @@ angular.module(ApplicationConfiguration.applicationModuleName).run(function ($ro //Then define the init function for starting up the application angular.element(document).ready(function () { //Fixing facebook bug with redirect - if (window.location.hash === '#_=_') { - window.location.hash = '#!'; + if (window.location.hash && window.location.hash === '#_=_') { + if (window.history && history.pushState) { + window.history.pushState('', document.title, window.location.pathname); + } else { + // Prevent scrolling by storing the page's current scroll offset + var scroll = { + top: document.body.scrollTop, + left: document.body.scrollLeft + }; + window.location.hash = ''; + // Restore the scroll offset, should be flicker free + document.body.scrollTop = scroll.top; + document.body.scrollLeft = scroll.left; + } } //Then init the app