Fixes group plan verify username (#10747)

Misc fixes
This commit is contained in:
Matteo Pagliazzi
2018-10-09 20:07:50 +02:00
committed by GitHub
parent 87cd000bb8
commit 36ead77e0c
2 changed files with 14 additions and 7 deletions

View File

@@ -72,9 +72,10 @@ api.updateUsername = {
api.verifyUsername = {
method: 'POST',
url: '/user/auth/verify-username',
middlewares: [authWithHeaders({
optional: true,
})],
async handler (req, res) {
const user = res.locals.user;
req.checkBody({
username: {
notEmpty: {errorMessage: res.t('missingUsername')},
@@ -84,11 +85,17 @@ api.verifyUsername = {
const validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors;
const issues = verifyUsername(req.body.username, res);
const user = res.locals.user;
const chosenUsername = req.body.username;
const existingUser = await User.findOne({ 'auth.local.lowerCaseUsername': req.body.username.toLowerCase() }, {auth: 1}).exec();
if (existingUser && existingUser._id !== user._id) {
issues.push(res.t('usernameTaken'));
const issues = verifyUsername(chosenUsername, res);
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 (issues.length > 0) {

View File

@@ -207,7 +207,7 @@ async function cancelGroupSubscriptionForUser (user, group, userWasRemoved = fal
if (user.purchased.plan.customerId !== this.constants.GROUP_PLAN_CUSTOMER_ID) return;
let userGroups = user.guilds.toObject();
userGroups.push('party');
if (user.party._id) userGroups.push(user.party._id);
let index = userGroups.indexOf(group._id);
userGroups.splice(index, 1);