Skip to content

Commit

Permalink
Merge branch 'refactor/profile_password_#17'
Browse files Browse the repository at this point in the history
Closes #17
  • Loading branch information
cleverbeagle committed Jul 31, 2017
2 parents 242ea49 + e8c221a commit a29343d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
14 changes: 1 addition & 13 deletions imports/api/Users/server/edit-profile.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
/* eslint-disable consistent-return */

import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';

let action;

const updatePassword = (userId, newPassword) => {
try {
throw new Meteor.Error('500', 'Testing failures.');
Accounts.setPassword(userId, newPassword, { logout: false });
} catch (exception) {
action.reject(`[editProfile.updatePassword] ${exception}`);
}
};

const updateUser = (userId, { emailAddress, profile }) => {
try {
Meteor.users.update(userId, {
Expand All @@ -30,15 +20,13 @@ const updateUser = (userId, { emailAddress, profile }) => {
const editProfile = ({ userId, profile }, promise) => {
try {
action = promise;

updateUser(userId, profile);
if (profile.password) updatePassword(userId, profile.password);
action.resolve();
} catch (exception) {
action.reject(`[editProfile.handler] ${exception}`);
}
};


export default options =>
new Promise((resolve, reject) =>
editProfile(options, { resolve, reject }));
1 change: 0 additions & 1 deletion imports/api/Users/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Meteor.methods({
'users.editProfile': function usersEditProfile(profile) {
check(profile, {
emailAddress: String,
password: Match.Optional(Object),
profile: {
name: {
first: String,
Expand Down
13 changes: 11 additions & 2 deletions imports/ui/pages/Profile/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,24 @@ class Profile extends React.Component {
},
};

if (this.newPassword.value) profile.password = Accounts._hashPassword(this.newPassword.value);

Meteor.call('users.editProfile', profile, (error) => {
if (error) {
Bert.alert(error.reason, 'danger');
} else {
Bert.alert('Profile updated!', 'success');
}
});

if (this.newPassword.value) {
Accounts.changePassword(this.currentPassword.value, this.newPassword.value, (error) => {
if (error) {
Bert.alert(error.reason, 'danger');
} else {
this.currentPassword.value = '';
this.newPassword.value = '';
}
});
}
}

renderOAuthUser(loading, user) {
Expand Down

0 comments on commit a29343d

Please sign in to comment.