Skip to content

Commit

Permalink
User image with gravatar implementation issue # 44
Browse files Browse the repository at this point in the history
  • Loading branch information
Syed Asher Ahmed committed Mar 28, 2017
1 parent 74bba8b commit c45e8b3
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ meteorhacks:aggregate
dfischer:phantomjs
meteorhacks:ssr
edgee:slingshot
msavin:mongol
msavin:mongol
jparker:gravatar
3 changes: 3 additions & 0 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ [email protected]
[email protected]
[email protected]
[email protected]
jparker:[email protected]
jparker:[email protected]
jparker:[email protected]
[email protected]
[email protected]
[email protected]
Expand Down
19 changes: 19 additions & 0 deletions imports/api/auth/methods.js
Original file line number Diff line number Diff line change
@@ -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;

});
19 changes: 18 additions & 1 deletion imports/startup/server/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
});
1 change: 1 addition & 0 deletions imports/startup/server/register-api.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
4 changes: 3 additions & 1 deletion imports/ui/components/AppLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ 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 (
<Layout>
<LeftMenu {...props}/>
<Panel>
<AppBarExtended>
<IconButton icon='menu' accent inverse={ true } onClick={ this.toggleDrawerActive.bind(this) }/>
<div className={theme.headerGreeting}>
<span>Welcome <b>{this.name()}</b> <img src = {this.state.avatar} width="45" height="45" /><i className="material-icons" onClick={this.logout.bind(this)}>&#xE8AC;</i></span>
<span>Welcome <b>{this.name()}</b> <img src = {this.state.avatar ? this.state.avatar : gravatar } width="45" height="45" /><i className="material-icons" onClick={this.logout.bind(this)}>&#xE8AC;</i></span>
</div>
</AppBarExtended>
<div className="page-content-wrapper" style={{ flex: 1, display: 'flex' }}>
Expand Down

0 comments on commit c45e8b3

Please sign in to comment.