add gravatar to profile

This commit is contained in:
Daniel Mills
2014-02-03 17:50:47 -05:00
parent 911cbf5685
commit f5ecfc507c
2 changed files with 41 additions and 29 deletions

View File

@ -1,5 +1,6 @@
var mongoose = require('mongoose');
var bcrypt = require('bcrypt-nodejs');
var crypto = require('crypto');
var userSchema = new mongoose.Schema({
email: { type: String, unique: true },
@ -48,4 +49,10 @@ userSchema.methods.comparePassword = function(candidatePassword, cb) {
});
};
userSchema.methods.gravatar = function() {
var md5 = crypto.createHash('md5');
md5.update(this.email);
return 'https://gravatar.com/avatar/' + md5.digest('hex').toString() + '?s=200';
};
module.exports = mongoose.model('User', userSchema);