salix/back/methods/vn-user/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',
2022-06-02 07:01:34 +00:00
type: 'number',
description: 'The user id',
http: {source: 'path'}
}, {
arg: 'oldPassword',
2022-06-02 07:01:34 +00:00
type: 'string',
description: 'The old password',
required: true
}, {
arg: 'newPassword',
2022-06-02 07:01:34 +00:00
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);
};
};