mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
@@ -72,9 +72,10 @@ api.updateUsername = {
|
|||||||
api.verifyUsername = {
|
api.verifyUsername = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/user/auth/verify-username',
|
url: '/user/auth/verify-username',
|
||||||
|
middlewares: [authWithHeaders({
|
||||||
|
optional: true,
|
||||||
|
})],
|
||||||
async handler (req, res) {
|
async handler (req, res) {
|
||||||
const user = res.locals.user;
|
|
||||||
|
|
||||||
req.checkBody({
|
req.checkBody({
|
||||||
username: {
|
username: {
|
||||||
notEmpty: {errorMessage: res.t('missingUsername')},
|
notEmpty: {errorMessage: res.t('missingUsername')},
|
||||||
@@ -84,11 +85,17 @@ api.verifyUsername = {
|
|||||||
const validationErrors = req.validationErrors();
|
const validationErrors = req.validationErrors();
|
||||||
if (validationErrors) throw 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();
|
const issues = verifyUsername(chosenUsername, res);
|
||||||
if (existingUser && existingUser._id !== user._id) {
|
|
||||||
issues.push(res.t('usernameTaken'));
|
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) {
|
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;
|
if (user.purchased.plan.customerId !== this.constants.GROUP_PLAN_CUSTOMER_ID) return;
|
||||||
|
|
||||||
let userGroups = user.guilds.toObject();
|
let userGroups = user.guilds.toObject();
|
||||||
userGroups.push('party');
|
if (user.party._id) userGroups.push(user.party._id);
|
||||||
|
|
||||||
let index = userGroups.indexOf(group._id);
|
let index = userGroups.indexOf(group._id);
|
||||||
userGroups.splice(index, 1);
|
userGroups.splice(index, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user