diff --git a/public/src/client/register.js b/public/src/client/register.js index 0a98b324fa..26096c29e1 100644 --- a/public/src/client/register.js +++ b/public/src/client/register.js @@ -159,14 +159,18 @@ define('forum/register', [ } else if (!utils.isUserNameValid(username) || !slugify(username)) { showError(username_notify, '[[error:invalid-username]]'); } else { - api.head(`/users/bySlug/${username}`, {}) - .then(() => { - showError(username_notify, '[[error:username-taken]]'); - }) - .catch(() => { + Promise.allSettled([ + api.head(`/users/bySlug/${username}`, {}), + api.head(`/groups/${username}`, {}), + ]).then((results) => { + if (results.every(obj => obj.status === 'rejected')) { showSuccess(username_notify, successIcon); - }) - .finally(callback); + } else { + showError(username_notify, '[[error:username-taken]]'); + } + + callback(); + }); } } diff --git a/public/src/modules/api.js b/public/src/modules/api.js index 207342d1c1..5438d3167f 100644 --- a/public/src/modules/api.js +++ b/public/src/modules/api.js @@ -42,7 +42,7 @@ define('api', () => { }); } - api.get = (route, payload = {}, onSuccess) => call({ + api.get = (route, payload, onSuccess) => call({ url: route + (Object.keys(payload).length ? ('?' + $.param(payload)) : ''), }, onSuccess); diff --git a/src/controllers/write/groups.js b/src/controllers/write/groups.js index d0e711aaa5..243d5b0cf7 100644 --- a/src/controllers/write/groups.js +++ b/src/controllers/write/groups.js @@ -6,6 +6,10 @@ const helpers = require('../helpers'); const Groups = module.exports; +Groups.exists = async (req, res) => { + helpers.formatApiResponse(200, res); +}; + Groups.create = async (req, res) => { const groupObj = await api.groups.create(req, req.body); helpers.formatApiResponse(200, res, groupObj); diff --git a/src/routes/write/groups.js b/src/routes/write/groups.js index 36c0a669f2..1f78447170 100644 --- a/src/routes/write/groups.js +++ b/src/routes/write/groups.js @@ -10,6 +10,7 @@ const setupApiRoute = routeHelpers.setupApiRoute; module.exports = function () { const middlewares = [middleware.authenticate]; + setupApiRoute(router, 'head', '/:slug', [middleware.assert.group], controllers.write.groups.exists); setupApiRoute(router, 'post', '/', [...middlewares, middleware.checkRequired.bind(null, ['name'])], controllers.write.groups.create); setupApiRoute(router, 'delete', '/:slug', [...middlewares, middleware.assert.group], controllers.write.groups.delete); setupApiRoute(router, 'put', '/:slug/membership/:uid', [...middlewares, middleware.assert.group], controllers.write.groups.join); diff --git a/src/socket.io/user.js b/src/socket.io/user.js index 292fb1ea48..cc39126d8a 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -30,7 +30,7 @@ require('./user/ban')(SocketUser); require('./user/registration')(SocketUser); SocketUser.exists = async function (socket, data) { - sockets.warnDeprecated(socket, 'HEAD /api/v3/users/bySlug/:userslug'); + sockets.warnDeprecated(socket, 'HEAD /api/v3/users/bySlug/:userslug *AND* HEAD /api/v3/groups/:slug'); if (!data || !data.username) { throw new Error('[[error:invalid-data]]');