commit
a29343d4fe
3 changed files with 12 additions and 16 deletions
|
|
@ -1,19 +1,9 @@
|
||||||
/* eslint-disable consistent-return */
|
/* eslint-disable consistent-return */
|
||||||
|
|
||||||
import { Meteor } from 'meteor/meteor';
|
import { Meteor } from 'meteor/meteor';
|
||||||
import { Accounts } from 'meteor/accounts-base';
|
|
||||||
|
|
||||||
let action;
|
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 }) => {
|
const updateUser = (userId, { emailAddress, profile }) => {
|
||||||
try {
|
try {
|
||||||
Meteor.users.update(userId, {
|
Meteor.users.update(userId, {
|
||||||
|
|
@ -30,15 +20,13 @@ const updateUser = (userId, { emailAddress, profile }) => {
|
||||||
const editProfile = ({ userId, profile }, promise) => {
|
const editProfile = ({ userId, profile }, promise) => {
|
||||||
try {
|
try {
|
||||||
action = promise;
|
action = promise;
|
||||||
|
|
||||||
updateUser(userId, profile);
|
updateUser(userId, profile);
|
||||||
if (profile.password) updatePassword(userId, profile.password);
|
action.resolve();
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
action.reject(`[editProfile.handler] ${exception}`);
|
action.reject(`[editProfile.handler] ${exception}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default options =>
|
export default options =>
|
||||||
new Promise((resolve, reject) =>
|
new Promise((resolve, reject) =>
|
||||||
editProfile(options, { resolve, reject }));
|
editProfile(options, { resolve, reject }));
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ Meteor.methods({
|
||||||
'users.editProfile': function usersEditProfile(profile) {
|
'users.editProfile': function usersEditProfile(profile) {
|
||||||
check(profile, {
|
check(profile, {
|
||||||
emailAddress: String,
|
emailAddress: String,
|
||||||
password: Match.Optional(Object),
|
|
||||||
profile: {
|
profile: {
|
||||||
name: {
|
name: {
|
||||||
first: String,
|
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) => {
|
Meteor.call('users.editProfile', profile, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
Bert.alert(error.reason, 'danger');
|
Bert.alert(error.reason, 'danger');
|
||||||
|
|
@ -101,6 +99,17 @@ class Profile extends React.Component {
|
||||||
Bert.alert('Profile updated!', 'success');
|
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) {
|
renderOAuthUser(loading, user) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue