feat(usernames): modal to force verification

This commit is contained in:
Sabe Jones
2018-10-13 12:53:16 -05:00
parent 6f5b9ef119
commit fa1fef11d6
10 changed files with 392 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
import { authWithHeaders } from '../../middlewares/auth';
import * as userLib from '../../libs/user';
import { verifyDisplayName } from '../../libs/user/validation';
const api = {};
@@ -206,4 +207,32 @@ api.userReset = {
},
};
api.verifyDisplayName = {
method: 'POST',
url: '/user/auth/verify-display-name',
middlewares: [authWithHeaders({
optional: true,
})],
async handler (req, res) {
req.checkBody({
displayName: {
notEmpty: {errorMessage: res.t('messageMissingDisplayName')},
},
});
const validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors;
const chosenDisplayName = req.body.displayName;
const issues = verifyDisplayName(chosenDisplayName, res);
if (issues.length > 0) {
res.respond(200, { isUsable: false, issues });
} else {
res.respond(200, { isUsable: true });
}
},
};
module.exports = api;