mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-16 07:00:53 -04:00
Refactored Gravatar mongoose method
This commit is contained in:
@@ -64,16 +64,15 @@ userSchema.methods.comparePassword = function(candidatePassword, cb) {
|
||||
* Used in Navbar and Account Management page.
|
||||
*/
|
||||
|
||||
userSchema.methods.gravatar = function(size, defaults) {
|
||||
userSchema.methods.gravatar = function(size) {
|
||||
if (!size) size = 200;
|
||||
if (!defaults) defaults = 'retro';
|
||||
|
||||
if (!this.email) {
|
||||
return 'https://gravatar.com/avatar/?s=' + size + '&d=' + defaults;
|
||||
return 'https://gravatar.com/avatar/?s=' + size + '&d=retro';
|
||||
}
|
||||
|
||||
var md5 = crypto.createHash('md5').update(this.email);
|
||||
return 'https://gravatar.com/avatar/' + md5.digest('hex').toString() + '?s=' + size + '&d=' + defaults;
|
||||
var md5 = crypto.createHash('md5').update(this.email).digest('hex');
|
||||
return 'https://gravatar.com/avatar/' + md5 + '?s=' + size + '&d=retro';
|
||||
};
|
||||
|
||||
module.exports = mongoose.model('User', userSchema);
|
||||
|
||||
Reference in New Issue
Block a user