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

65 lines
1.7 KiB
JavaScript
Raw Normal View History

module.exports = Self => {
Self.remoteMethod('changePassword', {
description: 'Changes the user password',
accepts: [
{
arg: 'ctx',
type: 'Object',
http: {source: 'context'}
}, {
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
}
],
returns: {
type: 'Boolean',
root: true
},
http: {
path: `/:id/changePassword`,
verb: 'PATCH'
}
});
Self.changePassword = async function(ctx, id, oldPassword, newPassword) {
let params = [id, oldPassword, newPassword];
await Self.rawSql(`CALL account.user_changePassword(?, ?, ?)`, params);
/*
const ldap = require('ldapjs');
let ldapConf = {
url: 'ldap://domain.local:389',
dn: 'cn=admin,dc=domain,dc=local',
password: '123456'
};
await new Promise((reject, resolve) => {
let client = ldap.createClient({url: ldapConf.url});
client.bind(ldapConf.dn, ldapConf.password, err => {
if (err)
reject(err);
else
resolve();
});
});
*/
return true;
};
};