Merge branch 'sabrecat/usernames-master' into develop

This commit is contained in:
Sabe Jones
2018-11-14 08:21:49 -06:00
62 changed files with 1850 additions and 594 deletions

View File

@@ -28,12 +28,14 @@ api.verifyUsername = {
const issues = verifyUsername(chosenUsername, res);
const existingUser = await User.findOne({
'auth.local.lowerCaseUsername': chosenUsername.toLowerCase(),
}, {auth: 1}).exec();
if (issues.length < 1) {
const existingUser = await User.findOne({
'auth.local.lowerCaseUsername': chosenUsername.toLowerCase(),
}, {auth: 1}).exec();
if (existingUser) {
if (!user || existingUser._id !== user._id) issues.push(res.t('usernameTaken'));
if (existingUser) {
if (!user || existingUser._id !== user._id) issues.push(res.t('usernameTaken'));
}
}
if (issues.length > 0) {

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;