Add button disable, persona detection, and mandatory encryption password
Co-authored-by: naielv <109038805+naielv@users.noreply.github.com>
This commit is contained in:
@@ -41,8 +41,8 @@ PAGES.login = {
|
|||||||
<label>Contraseña
|
<label>Contraseña
|
||||||
<input type="password" id="${field_couch_pass}" value="${localStorage.getItem('TELESEC_COUCH_PASS') || ''}"><br><br>
|
<input type="password" id="${field_couch_pass}" value="${localStorage.getItem('TELESEC_COUCH_PASS') || ''}"><br><br>
|
||||||
</label>
|
</label>
|
||||||
<label>Clave de encriptación (opcional)
|
<label>Clave de encriptación <span style="color: red;">*</span>
|
||||||
<input type="password" id="${field_secret}" value="${localStorage.getItem('TELESEC_SECRET') || ''}"><br><br>
|
<input type="password" id="${field_secret}" value="${localStorage.getItem('TELESEC_SECRET') || ''}" required><br><br>
|
||||||
</label>
|
</label>
|
||||||
<button id="${btn_skip}-save" class="btn5">Guardar y Continuar</button>
|
<button id="${btn_skip}-save" class="btn5">Guardar y Continuar</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
@@ -60,8 +60,17 @@ PAGES.login = {
|
|||||||
|
|
||||||
document.getElementById(btn_skip).onclick = () => {
|
document.getElementById(btn_skip).onclick = () => {
|
||||||
// Continue to persona creation without server config
|
// Continue to persona creation without server config
|
||||||
|
// Check if personas already exist (shouldn't happen but safety check)
|
||||||
|
var hasPersonas = Object.keys(SC_Personas).length > 0;
|
||||||
|
if (hasPersonas) {
|
||||||
|
toastr.info('Ya existen personas. Saltando creación de cuenta.');
|
||||||
|
localStorage.setItem('TELESEC_ONBOARDING_COMPLETE', 'true');
|
||||||
|
open_page('login');
|
||||||
|
setUrlHash('login');
|
||||||
|
} else {
|
||||||
open_page('login,onboarding-persona');
|
open_page('login,onboarding-persona');
|
||||||
setUrlHash('login,onboarding-persona');
|
setUrlHash('login,onboarding-persona');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
document.getElementById(btn_skip + '-save').onclick = () => {
|
document.getElementById(btn_skip + '-save').onclick = () => {
|
||||||
@@ -69,13 +78,18 @@ PAGES.login = {
|
|||||||
var dbname = document.getElementById(field_couch_dbname).value.trim();
|
var dbname = document.getElementById(field_couch_dbname).value.trim();
|
||||||
var user = document.getElementById(field_couch_user).value.trim();
|
var user = document.getElementById(field_couch_user).value.trim();
|
||||||
var pass = document.getElementById(field_couch_pass).value;
|
var pass = document.getElementById(field_couch_pass).value;
|
||||||
var secret = document.getElementById(field_secret).value || '';
|
var secret = document.getElementById(field_secret).value.trim();
|
||||||
|
|
||||||
if (!url) {
|
if (!url) {
|
||||||
toastr.error('Por favor ingresa un servidor CouchDB');
|
toastr.error('Por favor ingresa un servidor CouchDB');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!secret) {
|
||||||
|
toastr.error('La clave de encriptación es obligatoria');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Normalize URL: add https:// if no protocol specified
|
// Normalize URL: add https:// if no protocol specified
|
||||||
var normalizedUrl = url;
|
var normalizedUrl = url;
|
||||||
if (!/^https?:\/\//i.test(url)) {
|
if (!/^https?:\/\//i.test(url)) {
|
||||||
@@ -86,19 +100,30 @@ PAGES.login = {
|
|||||||
localStorage.setItem('TELESEC_COUCH_DBNAME', dbname);
|
localStorage.setItem('TELESEC_COUCH_DBNAME', dbname);
|
||||||
localStorage.setItem('TELESEC_COUCH_USER', user);
|
localStorage.setItem('TELESEC_COUCH_USER', user);
|
||||||
localStorage.setItem('TELESEC_COUCH_PASS', pass);
|
localStorage.setItem('TELESEC_COUCH_PASS', pass);
|
||||||
if (secret) {
|
|
||||||
localStorage.setItem('TELESEC_SECRET', secret.toUpperCase());
|
localStorage.setItem('TELESEC_SECRET', secret.toUpperCase());
|
||||||
SECRET = secret.toUpperCase();
|
SECRET = secret.toUpperCase();
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DB.init({ secret: SECRET, remoteServer: normalizedUrl, username: user, password: pass, dbname: dbname || undefined });
|
DB.init({ secret: SECRET, remoteServer: normalizedUrl, username: user, password: pass, dbname: dbname || undefined });
|
||||||
toastr.success('Servidor configurado correctamente');
|
toastr.success('Servidor configurado correctamente');
|
||||||
// Continue to persona creation
|
|
||||||
|
// Wait a moment for initial replication to pull personas
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
// Check if personas were replicated from server
|
||||||
|
var hasPersonas = Object.keys(SC_Personas).length > 0;
|
||||||
|
|
||||||
|
if (hasPersonas) {
|
||||||
|
// Personas found from server, skip persona creation step
|
||||||
|
toastr.info('Se encontraron personas en el servidor. Saltando creación de cuenta.');
|
||||||
|
localStorage.setItem('TELESEC_ONBOARDING_COMPLETE', 'true');
|
||||||
|
open_page('login');
|
||||||
|
setUrlHash('login');
|
||||||
|
} else {
|
||||||
|
// No personas found, continue to persona creation
|
||||||
open_page('login,onboarding-persona');
|
open_page('login,onboarding-persona');
|
||||||
setUrlHash('login,onboarding-persona');
|
setUrlHash('login,onboarding-persona');
|
||||||
}, 500);
|
}
|
||||||
|
}, 2000);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toastr.error('Error al configurar el servidor: ' + (e.message || e));
|
toastr.error('Error al configurar el servidor: ' + (e.message || e));
|
||||||
}
|
}
|
||||||
@@ -109,6 +134,16 @@ PAGES.login = {
|
|||||||
var field_nombre = safeuuid();
|
var field_nombre = safeuuid();
|
||||||
var btn_crear = safeuuid();
|
var btn_crear = safeuuid();
|
||||||
|
|
||||||
|
// Check if personas already exist
|
||||||
|
var hasPersonas = Object.keys(SC_Personas).length > 0;
|
||||||
|
if (hasPersonas) {
|
||||||
|
toastr.info('Se detectaron personas existentes. Redirigiendo al login.');
|
||||||
|
localStorage.setItem('TELESEC_ONBOARDING_COMPLETE', 'true');
|
||||||
|
open_page('login');
|
||||||
|
setUrlHash('login');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
container.innerHTML = `
|
container.innerHTML = `
|
||||||
<h1>¡Bienvenido a TeleSec! 🎉</h1>
|
<h1>¡Bienvenido a TeleSec! 🎉</h1>
|
||||||
<h2>Paso 2: Crea tu cuenta de administrador</h2>
|
<h2>Paso 2: Crea tu cuenta de administrador</h2>
|
||||||
@@ -129,6 +164,12 @@ PAGES.login = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disable button to prevent duplicate creation
|
||||||
|
var btnElement = document.getElementById(btn_crear);
|
||||||
|
btnElement.disabled = true;
|
||||||
|
btnElement.style.opacity = '0.5';
|
||||||
|
btnElement.innerText = 'Creando...';
|
||||||
|
|
||||||
// Create persona with all admin permissions from PERMS object
|
// Create persona with all admin permissions from PERMS object
|
||||||
var allPerms = Object.keys(PERMS).join(',') + ',';
|
var allPerms = Object.keys(PERMS).join(',') + ',';
|
||||||
var personaId = safeuuid('admin-');
|
var personaId = safeuuid('admin-');
|
||||||
@@ -157,6 +198,10 @@ PAGES.login = {
|
|||||||
}, 500);
|
}, 500);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
toastr.error('Error creando cuenta: ' + (e.message || e));
|
toastr.error('Error creando cuenta: ' + (e.message || e));
|
||||||
|
// Re-enable button on error
|
||||||
|
btnElement.disabled = false;
|
||||||
|
btnElement.style.opacity = '1';
|
||||||
|
btnElement.innerText = 'Crear cuenta y empezar';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user