v1.18.x
Barış Soner Uşaklı 4 years ago
commit 0b30efba31

@ -159,14 +159,18 @@ define('forum/register', [
} else if (!utils.isUserNameValid(username) || !slugify(username)) { } else if (!utils.isUserNameValid(username) || !slugify(username)) {
showError(username_notify, '[[error:invalid-username]]'); showError(username_notify, '[[error:invalid-username]]');
} else { } else {
api.head(`/users/bySlug/${username}`, {}) Promise.allSettled([
.then(() => { api.head(`/users/bySlug/${username}`, {}),
showError(username_notify, '[[error:username-taken]]'); api.head(`/groups/${username}`, {}),
}) ]).then((results) => {
.catch(() => { if (results.every(obj => obj.status === 'rejected')) {
showSuccess(username_notify, successIcon); showSuccess(username_notify, successIcon);
}) } else {
.finally(callback); showError(username_notify, '[[error:username-taken]]');
}
callback();
});
} }
} }

@ -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)) : ''), url: route + (Object.keys(payload).length ? ('?' + $.param(payload)) : ''),
}, onSuccess); }, onSuccess);

@ -6,6 +6,10 @@ const helpers = require('../helpers');
const Groups = module.exports; const Groups = module.exports;
Groups.exists = async (req, res) => {
helpers.formatApiResponse(200, res);
};
Groups.create = async (req, res) => { Groups.create = async (req, res) => {
const groupObj = await api.groups.create(req, req.body); const groupObj = await api.groups.create(req, req.body);
helpers.formatApiResponse(200, res, groupObj); helpers.formatApiResponse(200, res, groupObj);

@ -10,6 +10,7 @@ const setupApiRoute = routeHelpers.setupApiRoute;
module.exports = function () { module.exports = function () {
const middlewares = [middleware.authenticate]; 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, '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, 'delete', '/:slug', [...middlewares, middleware.assert.group], controllers.write.groups.delete);
setupApiRoute(router, 'put', '/:slug/membership/:uid', [...middlewares, middleware.assert.group], controllers.write.groups.join); setupApiRoute(router, 'put', '/:slug/membership/:uid', [...middlewares, middleware.assert.group], controllers.write.groups.join);

@ -30,7 +30,7 @@ require('./user/ban')(SocketUser);
require('./user/registration')(SocketUser); require('./user/registration')(SocketUser);
SocketUser.exists = async function (socket, data) { 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) { if (!data || !data.username) {
throw new Error('[[error:invalid-data]]'); throw new Error('[[error:invalid-data]]');

Loading…
Cancel
Save