35 lines
1020 B
JavaScript
35 lines
1020 B
JavaScript
|
|
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'
|
|
}
|
|
});
|
|
|
|
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);
|
|
};
|
|
};
|