From 6cae78702579e5d6b03ae943a20e1a449709c043 Mon Sep 17 00:00:00 2001 From: Syed Asher Ahmed Date: Sat, 15 Apr 2017 11:50:40 +0000 Subject: [PATCH] Setting gravatar on Email update && bug fixing issue #44 --- imports/api/settings/methods.js | 6 ++++ imports/ui/components/settings/Settings.jsx | 35 +++++++++++---------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/imports/api/settings/methods.js b/imports/api/settings/methods.js index 927cfb8..0bacfc2 100644 --- a/imports/api/settings/methods.js +++ b/imports/api/settings/methods.js @@ -89,6 +89,12 @@ export const updateProfile = new ValidatedMethod({ update['emails.0.address'] = users.email; } Meteor.users.update({_id: Meteor.userId()} , {$set: update}); + + if(users.email){ + Meteor.users.update( { _id: Meteor.user()._id }, { + $set: { "profile.md5hash": Gravatar.hash( users.email ) } + }); + } } }); diff --git a/imports/ui/components/settings/Settings.jsx b/imports/ui/components/settings/Settings.jsx index e512026..3efdac7 100755 --- a/imports/ui/components/settings/Settings.jsx +++ b/imports/ui/components/settings/Settings.jsx @@ -211,22 +211,25 @@ class SettingsPage extends Component { folder: "profiles", uploaderId: userId }; - let uploader = new Slingshot.Upload('imageUploader', metaContext); - uploader.send(this.state.target, (error, downloadUrl) => { // you can use refs if you like - if (error) { - // Log service detailed response - console.error('Error uploading', uploader.xhr.response); - alert (error); // you may want to fancy this up when you're ready instead of a popup. - } - else { - // we use $set because the user can change their avatar so it overwrites the url :) - Meteor.users.update(Meteor.userId(), {$set: {"profile.avatar": downloadUrl}}); - console.log(downloadUrl); - this.setState({imageUrl: downloadUrl}); - this.resetImageUpload(); - } - - }); + if(this.state.target && this.uploadImageName != this.state.target.name) { + this.uploadImageName = this.state.target.name; + + let uploader = new Slingshot.Upload('imageUploader', metaContext); + uploader.send(this.state.target, (error, downloadUrl) => { // you can use refs if you like + if (error) { + // Log service detailed response + console.error('Error uploading', uploader.xhr.response); + alert(error); // you may want to fancy this up when you're ready instead of a popup. + } + else { + // we use $set because the user can change their avatar so it overwrites the url :) + Meteor.users.update(Meteor.userId(), {$set: {"profile.avatar": downloadUrl}}); + console.log(downloadUrl); + this.setState({imageUrl: downloadUrl}); + } + this.resetImageUpload(); + }); + } } updateAccountSettings (event) {