check for null email for gravatar

This commit is contained in:
Daniel Mills
2014-02-14 00:14:21 -05:00
parent 045f6d46df
commit c5a5b4fb9f

View File

@ -56,6 +56,11 @@ userSchema.methods.comparePassword = function(candidatePassword, cb) {
userSchema.methods.gravatar = function(size, defaults) {
if (!size) size = 200;
if (!defaults) defaults = 'retro';
if(!this.email) {
return 'https://gravatar.com/avatar/?s=' + size + '&d=' + defaults;
}
var md5 = crypto.createHash('md5').update(this.email);
return 'https://gravatar.com/avatar/' + md5.digest('hex').toString() + '?s=' + size + '&d=' + defaults;
};