javascript - Meteor: Turning email address into MD5hash on server, and accessing on client -


so want use gravatar avatars on website. got appropriate packages it. way works, turns email addresses "md5hash." that's sent gravatar in exchange image url.

fine, want display avatars without exposing everyone's email address. @ same time, have users already have gravatars, , think cool if avatars popped 1 day, without adding field user profiles collection, or asking them to.

is there way of on server , accomplish goal?

handlebars.registerhelper("gravatar", function(id){     var email = meteor.users.findone({_id: id}).emails[0].address;     var options = {          secure: true,         size: 29,         default: 'retro'     };      var md5hash = gravatar.hash(email);     // 5658ffccee7f0ebfda2b226238b1eb6e      var url = gravatar.imageurl(md5hash, options);     // https://secure.gravatar.com/avatar/5658ffccee7f0ebfda2b226238b1eb6e     return url; }); 

hackish:

on server:

userarray = meteor.users.find(query,{fields: {"emails.address": 1}}).fetch(); userarray.foreach(function(el,i,a){   a[i] = { _id: el._id, md5hash: gravatar.hash(el.emails[0].address) }; } 

where query whatever criteria are, array of objects _id matches _id of each user , md5hash value hash of user's email. can set method return array when need it.

the news client can use these hashes avatars in whatever sizes might necessary @ time.

much less hackish:

the problem above server going recomputing md5hash of each email. plus you're getting potentially big , non-reactive array server. you'll live regret this. want add md5hash key emails array in user document, initialize existing users, , make sure new users have key set @ creation time. let handle either single-email address users or multiple-email address users.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -