feat: add server-side username validation

This commit is contained in:
Oliver Eyton-Williams
2019-11-11 19:59:36 +01:00
committed by mrugesh
parent 7500c370b6
commit e77408827a

View File

@ -4,6 +4,7 @@ import { check } from 'express-validator/check';
import { ifNoUser401, createValidatorErrorHandler } from '../utils/middleware'; import { ifNoUser401, createValidatorErrorHandler } from '../utils/middleware';
import { themes } from '../../common/utils/themes.js'; import { themes } from '../../common/utils/themes.js';
import { alertTypes } from '../../common/utils/flash.js'; import { alertTypes } from '../../common/utils/flash.js';
import { validate } from '../../../utils/validate';
const log = debug('fcc:boot:settings'); const log = debug('fcc:boot:settings');
@ -199,6 +200,15 @@ function createUpdateMyUsername(app) {
message: 'Username is already associated with this account' message: 'Username is already associated with this account'
}); });
} }
const validation = validate(username);
if (!validation.valid) {
return res.json({
type: 'info',
message: `Username ${username} ${validation.error}`
});
}
const exists = await User.doesExist(username); const exists = await User.doesExist(username);
if (exists) { if (exists) {