add support for profile
This commit is contained in:
parent
779e3ee978
commit
252ebf50cc
7 changed files with 268 additions and 1 deletions
43
imports/modules/server/edit-profile.js
Normal file
43
imports/modules/server/edit-profile.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* eslint-disable consistent-return */
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Accounts } from 'meteor/accounts-base';
|
||||
|
||||
let action;
|
||||
|
||||
const updatePassword = (userId, newPassword) => {
|
||||
try {
|
||||
Accounts.setPassword(userId, newPassword, { logout: false });
|
||||
} catch (exception) {
|
||||
action.reject(`[editProfile.updatePassword] ${exception}`);
|
||||
}
|
||||
};
|
||||
|
||||
const updateUser = (userId, { emailAddress, profile }) => {
|
||||
try {
|
||||
Meteor.users.update(userId, {
|
||||
$set: {
|
||||
'emails.0.address': emailAddress,
|
||||
profile,
|
||||
},
|
||||
});
|
||||
} catch (exception) {
|
||||
action.reject(`[editProfile.updateUser] ${exception}`);
|
||||
}
|
||||
};
|
||||
|
||||
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 }));
|
||||
Loading…
Add table
Add a link
Reference in a new issue