Add route to let admin set user password

This commit is contained in:
Girish Ramakrishnan
2018-08-31 14:30:00 -07:00
parent 2c3f1ab720
commit 43055da614
3 changed files with 63 additions and 9 deletions

View File

@@ -6,6 +6,7 @@ exports = module.exports = {
list: list,
create: create,
remove: remove,
changePassword: changePassword,
verifyPassword: verifyPassword,
createInvite: createInvite,
sendInvite: sendInvite,
@@ -186,4 +187,19 @@ function transferOwnership(req, res, next) {
next(new HttpSuccess(200, {}));
});
}
}
function changePassword(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
assert.strictEqual(typeof req.params.userId, 'string');
if (typeof req.body.password !== 'string') return next(new HttpError(400, 'password must be a string'));
users.setPassword(req.params.userId, req.body.password, function (error) {
if (error && error.reason === UsersError.BAD_FIELD) return next(new HttpError(400, error.message));
if (error && error.reason === UsersError.NOT_FOUND) return next(new HttpError(404, 'User not found'));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(204));
});
}