Files
ap_pos/setup.js
Marco Gallegos 4a841917f8 feat: Add initial setup page and functionality for admin account creation
- Created setup.html for the initial configuration of the admin account.
- Implemented setup.js to handle form submission and validation.
- Added logo images for branding.
- Introduced storage.js for API data handling (load, save, remove).
- Added styles.css for consistent styling across the application.
2025-08-25 08:01:30 -06:00

36 lines
1.3 KiB
JavaScript

document.getElementById('setupForm').addEventListener('submit', async (e) => {
e.preventDefault();
const name = document.getElementById('fullName').value;
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
const confirmPassword = document.getElementById('confirmPassword').value;
const errorMessage = document.getElementById('error-message');
if (password !== confirmPassword) {
errorMessage.textContent = 'Las contraseñas no coinciden.';
return;
}
try {
const response = await fetch('/api/setup', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name, username, password })
});
const result = await response.json();
if (response.ok) {
alert('Cuenta de administrador creada exitosamente. Ahora serás redirigido a la página de inicio de sesión.');
window.location.href = '/login.html';
} else {
errorMessage.textContent = result.error || 'Ocurrió un error al crear la cuenta.';
}
} catch (error) {
errorMessage.textContent = 'Error de conexión con el servidor.';
console.error('Error en el setup:', error);
}
});