salix/back/methods/account/change-password.js

35 lines
1020 B
JavaScript
Raw Normal View History

module.exports = Self => {
Self.remoteMethod('changePassword', {
description: 'Changes the user password',
accepts: [
{
arg: 'id',
type: 'Number',
description: 'The user id',
http: {source: 'path'}
}, {
arg: 'oldPassword',
type: 'String',
description: 'The old password',
required: true
}, {
arg: 'newPassword',
type: 'String',
description: 'The new password',
required: true
}
],
http: {
path: `/:id/changePassword`,
verb: 'PATCH'
}
});
2020-09-21 11:24:43 +00:00
Self.changePassword = async function(id, oldPassword, newPassword) {
await Self.rawSql(`CALL account.user_changePassword(?, ?, ?)`,
[id, oldPassword, newPassword]);
await Self.app.models.UserAccount.syncById(id, newPassword);
};
};