mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user