Handle more 2fa route errors

This commit is contained in:
Johannes Zellner
2018-04-26 16:14:37 +02:00
parent 9cd6333cf7
commit fbba636fb3
2 changed files with 6 additions and 3 deletions

View File

@@ -87,6 +87,9 @@ function enableTwoFactorAuthentication(req, res, next) {
if (!req.body.totpToken || typeof req.body.totpToken !== 'string') return next(new HttpError(400, 'totpToken must be a nonempty string'));
user.enableTwoFactorAuthentication(req.user.id, req.body.totpToken, function (error) {
if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(404, 'User not found'));
if (error && error.reason === UserError.BAD_TOKEN) return next(new HttpError(403, 'Invalid token'));
if (error && error.reason === UserError.ALREADY_EXISTS) return next(new HttpError(409, 'TwoFactor Authentication is already enabled'));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(202, {}));
});