commit
a29343d4fe
3 changed files with 12 additions and 16 deletions
|
|
@ -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, {
|
||||
|
|
@ -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 }));
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ Meteor.methods({
|
|||
'users.editProfile': function usersEditProfile(profile) {
|
||||
check(profile, {
|
||||
emailAddress: String,
|
||||
password: Match.Optional(Object),
|
||||
profile: {
|
||||
name: {
|
||||
first: String,
|
||||
|
|
|
|||
|
|
@ -92,8 +92,6 @@ 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');
|
||||
|
|
@ -101,6 +99,17 @@ class Profile extends React.Component {
|
|||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue