From c45e8b3ee1e918e510ad0a04a7ec977a3fbc4aae Mon Sep 17 00:00:00 2001 From: Syed Asher Ahmed Date: Tue, 28 Mar 2017 19:40:47 +0000 Subject: [PATCH] User image with gravatar implementation issue # 44 --- .meteor/packages | 3 ++- .meteor/versions | 3 +++ imports/api/auth/methods.js | 19 +++++++++++++++++++ imports/startup/server/fixtures.js | 19 ++++++++++++++++++- imports/startup/server/register-api.js | 1 + imports/ui/components/AppLayout.jsx | 4 +++- 6 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 imports/api/auth/methods.js diff --git a/.meteor/packages b/.meteor/packages index 0027bed..c44314c 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -32,4 +32,5 @@ meteorhacks:aggregate dfischer:phantomjs meteorhacks:ssr edgee:slingshot -msavin:mongol \ No newline at end of file +msavin:mongol +jparker:gravatar diff --git a/.meteor/versions b/.meteor/versions index ccd2add..7c9bf29 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -43,6 +43,9 @@ html-tools@1.0.10 htmljs@1.0.10 http@1.2.9 id-map@1.0.9 +jparker:crypto-core@0.1.0 +jparker:crypto-md5@0.1.1 +jparker:gravatar@0.5.1 jquery@1.11.10 launch-screen@1.0.12 less@2.7.5 diff --git a/imports/api/auth/methods.js b/imports/api/auth/methods.js new file mode 100644 index 0000000..4d4e4e9 --- /dev/null +++ b/imports/api/auth/methods.js @@ -0,0 +1,19 @@ +// methods related to signUp and Login + +import { Meteor } from 'meteor/meteor'; +import { Accounts as MeteorAccounts } from 'meteor/accounts-base' +import { Accounts } from '../accounts/accounts.js'; + + + +MeteorAccounts.onCreateUser(function(options, user) { + var account = {owner: user._id}; + //Inserting default bank account on signup + Accounts.insert({owner: account.owner, bank: 'bank-Default', country: 'PK', purpose: 'Bank Account', icon: 'abc' }); + //Reset user object + if (options.profile) + user.profile = options.profile; + user.profile.md5hash = Gravatar.hash( user.emails[0].address ); + return user; + +}); \ No newline at end of file diff --git a/imports/startup/server/fixtures.js b/imports/startup/server/fixtures.js index 74139ed..a565222 100755 --- a/imports/startup/server/fixtures.js +++ b/imports/startup/server/fixtures.js @@ -4,7 +4,24 @@ import { Meteor } from 'meteor/meteor'; import { Accounts } from '../../api/accounts/accounts.js'; + +function setGravatars() { + let users = Meteor.users.find( { md5hash: { $exists: false } } ); + users.forEach( ( user ) => { + console.log("user"); + console.log(user); + if(user.emails.length) + Meteor.users.update( { _id: user._id }, { + $set: { "profile.md5hash": Gravatar.hash( user.emails[0].address ) } + }); + }); +} + + + + + // if the database is empty on server start, create some sample data. Meteor.startup(() => { - + setGravatars() }); \ No newline at end of file diff --git a/imports/startup/server/register-api.js b/imports/startup/server/register-api.js index 2f39ac0..c1eef49 100755 --- a/imports/startup/server/register-api.js +++ b/imports/startup/server/register-api.js @@ -1,6 +1,7 @@ // This defines all the collections, publications and methods that the application provides // as an API to the client. +import '../../api/auth/methods.js'; import '../../api/accounts/methods.js'; import '../../api/accounts/server/publications.js'; diff --git a/imports/ui/components/AppLayout.jsx b/imports/ui/components/AppLayout.jsx index b956f9c..81611a4 100755 --- a/imports/ui/components/AppLayout.jsx +++ b/imports/ui/components/AppLayout.jsx @@ -56,6 +56,8 @@ export default class AppLayout extends Component { toggleDrawerActive: this.toggleDrawerActive.bind(this), drawerActive: this.state.drawerActive }; + if(Meteor.user && Meteor.user().profile.md5hash){ + var gravatar = Gravatar.imageUrl( Meteor.user().profile.md5hash, { secure: true, size: "48", d: 'mm', rating: 'pg' } );} return ( @@ -63,7 +65,7 @@ export default class AppLayout extends Component {
- Welcome {this.name()} + Welcome {this.name()}