Skip to content

Commit

Permalink
Setting gravatar on Email update && bug fixing issue #44
Browse files Browse the repository at this point in the history
  • Loading branch information
Syed Asher Ahmed committed Apr 15, 2017
1 parent 3ad3c30 commit 6cae787
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
6 changes: 6 additions & 0 deletions imports/api/settings/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) }
});
}
}
});

35 changes: 19 additions & 16 deletions imports/ui/components/settings/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6cae787

Please sign in to comment.