Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #842 from Gym/fb-enhancements
Browse files Browse the repository at this point in the history
Facebook authentication
  • Loading branch information
lirantal committed Aug 25, 2015
2 parents 2b015b0 + b249512 commit 05355b9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 14 additions & 2 deletions modules/core/client/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,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
Expand Down
15 changes: 14 additions & 1 deletion modules/users/server/config/strategies/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 05355b9

Please sign in to comment.