forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pull in user image on signup when available
- Loading branch information
Berkeley Martinez
authored and
Berkeley Martinez
committed
Jun 11, 2015
1 parent
4d8ab0a
commit fe5cbec
Showing
3 changed files
with
40 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
// var debug = require('debug')('freecc:models:userIdent'); | ||
// | ||
// module.exports = function(UserIdent) { | ||
// | ||
// UserIdent.observe('before save', function(ctx, next) { | ||
// | ||
// var userIdent = ctx.instance; | ||
// userIdent.user(function(err, user) { | ||
// if (err) { return next(err); } | ||
// debug('got user', user.username); | ||
// | ||
// // check if user has picture | ||
// // set user.picture from twitter | ||
// if (!user.picture) { | ||
// debug('use has no pic'); | ||
// user.picture = userIdent.profile.photos[0].value; | ||
// user.save(function(err) { | ||
// if (err) { return next(err); } | ||
// next(); | ||
// }); | ||
// } else { | ||
// debug('exiting after user ident'); | ||
// next(); | ||
// } | ||
// }); | ||
// }); | ||
// }; | ||
var debug = require('debug')('freecc:models:userIdent'); | ||
|
||
var defaultProfileImage = | ||
require('../utils/constantStrings.json').defaultProfileImage; | ||
|
||
module.exports = function(UserIdent) { | ||
|
||
UserIdent.observe('before save', function(ctx, next) { | ||
var userIdent = ctx.currentInstance; | ||
// treat userIdent as immutable | ||
userIdent.user(function(err, user) { | ||
if (err) { return next(err); } | ||
debug('got user', user.username); | ||
|
||
var picture = userIdent.profile && userIdent.profile[0] ? | ||
userIdent.profile[0].value : | ||
null; | ||
|
||
// check if user has picture | ||
// set user.picture from twitter | ||
if (picture && !user.picture || user.picture === defaultProfileImage) { | ||
debug('use has no pic'); | ||
user.picture = userIdent.profile.photos[0].value; | ||
user.save(function(err) { | ||
if (err) { return next(err); } | ||
next(); | ||
}); | ||
} else { | ||
debug('exiting after user ident'); | ||
next(); | ||
} | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"defaultProfileImage": "https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters