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);
|
|
};
|
|
};
|