Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions public/src/client/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ define('forum/register', [
$('#username').trigger('focus');
};

// Función para generar sugerencias de nombres de usuario alternativos
function suggestUsernameAlternatives(username) {
const suffixes = ['suffix'];
return suffixes.map(suffix => username + suffix);
}


function validateUsername(username, callback) {
callback = callback || function () {};

Expand All @@ -132,17 +139,30 @@ define('forum/register', [
api.head(`/users/bySlug/${userslug}`, {}),
api.head(`/groups/${username}`, {}),
]).then((results) => {
if (results.every(obj => obj.status === 'rejected')) {
showSuccess(usernameInput, username_notify, successIcon);
const userSlugCheck = results[0]; // Verificación del usuario por slug
const groupCheck = results[1]; // Verificación del grupo por nombre

if (userSlugCheck.status === 'fulfilled') {
// El slug ya está en uso por otro usuario
const suggestions = suggestUsernameAlternatives(username);
const suggestionText = `[[error:username-taken]]. Maybe try ${suggestions.join(', ')}`;
showError(usernameInput, username_notify, suggestionText);

// showError(usernameInput, username_notify, '[[error:username-taken-by-user]]');

} else if (groupCheck.status === 'fulfilled') {
// El nombre ya está en uso por un grupo
showError(usernameInput, username_notify, '[[error:username-taken-by-group]]');
} else {
showError(usernameInput, username_notify, '[[error:username-taken]]');
// Si ninguna de las verificaciones fue exitosa, significa que el nombre está disponible
showSuccess(usernameInput, username_notify, successIcon);
}

callback();
});
}
}


function validatePassword(password, password_confirm) {
const passwordInput = $('#password');
const password_notify = $('#password-notify');
Expand Down