user: load the resource with middleware

This commit is contained in:
Girish Ramakrishnan
2020-02-13 20:45:00 -08:00
parent 938ca6402c
commit d1911be28c
9 changed files with 120 additions and 134 deletions

View File

@@ -133,7 +133,7 @@ function setupAccount(req, res, next) {
users.getByResetToken(req.body.resetToken, function (error, userObject) {
if (error) return next(new HttpError(401, 'Invalid Reset Token'));
users.update(userObject.id, { username: req.body.username, displayName: req.body.displayName }, auditSource.fromRequest(req), function (error) {
users.update(userObject, { username: req.body.username, displayName: req.body.displayName }, auditSource.fromRequest(req), function (error) {
if (error && error.reason === BoxError.ALREADY_EXISTS) return next(new HttpError(409, 'Username already used'));
if (error && error.reason === BoxError.BAD_FIELD) return next(new HttpError(400, error.message));
if (error && error.reason === BoxError.NOT_FOUND) return next(new HttpError(404, 'No such user'));