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.
|
* Used in Navbar and Account Management page.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
userSchema.methods.gravatar = function(size, defaults) {
|
userSchema.methods.gravatar = function(size) {
|
||||||
if (!size) size = 200;
|
if (!size) size = 200;
|
||||||
if (!defaults) defaults = 'retro';
|
|
||||||
|
|
||||||
if (!this.email) {
|
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);
|
var md5 = crypto.createHash('md5').update(this.email).digest('hex');
|
||||||
return 'https://gravatar.com/avatar/' + md5.digest('hex').toString() + '?s=' + size + '&d=' + defaults;
|
return 'https://gravatar.com/avatar/' + md5 + '?s=' + size + '&d=retro';
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = mongoose.model('User', userSchema);
|
module.exports = mongoose.model('User', userSchema);
|
||||||
|
Reference in New Issue
Block a user