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)) {
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();
});
}
}

@ -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);

@ -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);

@ -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);

@ -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]]');

Loading…
Cancel
Save