mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
feat(usernames): modal to force verification
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user