Usuario o contraseña incorrectos.
Lerner Capital
Admin
A
Admin
Administrador
Gestión de usuarios
Administrá quién puede ingresar y a qué módulos tiene acceso.
Nuevo usuario
let currentUser = null; async function supaFetch(path, options = {}) { const res = await fetch(`${SUPA_URL}/rest/v1/${path}`, { headers: { 'apikey': SUPA_KEY, 'Authorization': `Bearer ${SUPA_KEY}`, 'Content-Type': 'application/json', 'Prefer': 'return=representation', ...options.headers }, ...options }); if (!res.ok) throw new Error(await res.text()); return res.json(); } async function verifyPassword(password, hash) { const res = await fetch(`${SUPA_URL}/rest/v1/rpc/verify_password`, { method: 'POST', headers: { 'apikey': SUPA_KEY, 'Authorization': `Bearer ${SUPA_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ plain: password, hashed: hash }) }); return res.json(); } async function doLogin() { const username = document.getElementById('username').value.trim(); const pass = document.getElementById('password').value; const errEl = document.getElementById('error-msg'); const btn = document.querySelector('.btn-login'); if (!username || !pass) { showError('Completá usuario y contraseña.'); return; } btn.disabled = true; btn.textContent = 'Ingresando…'; errEl.style.display = 'none'; try { const rows = await supaFetch(`internal_users?username=eq.${encodeURIComponent(username)}&activo=eq.true&select=id,username,email,rol,password_hash`); if (!rows.length) { showError('Usuario o contraseña incorrectos.'); return; } const user = rows[0]; const ok = await verifyPassword(pass, user.password_hash); if (!ok) { showError('Usuario o contraseña incorrectos.'); return; } await supaFetch(`internal_users?id=eq.${user.id}`, { method: 'PATCH', body: JSON.stringify({ ultimo_acceso: new Date().toISOString() }) }).catch(() => {}); currentUser = { id: user.id, username: user.username, email: user.email, rol: user.rol }; sessionStorage.setItem('lerner_session', JSON.stringify(currentUser)); document.getElementById('user-display-name').textContent = user.username; document.getElementById('user-avatar-initials').textContent = user.username.charAt(0).toUpperCase(); document.getElementById('login-screen').style.display = 'none'; document.getElementById('dashboard').style.display = 'block'; } catch (e) { showError('Error de conexión. Intentá de nuevo.'); } finally { btn.disabled = false; btn.textContent = 'Ingresar'; } } function showError(msg) { const el = document.getElementById('error-msg'); el.textContent = msg; el.style.display = 'block'; } function doLogout() { sessionStorage.removeItem('lerner_session'); currentUser = null; document.getElementById('dashboard').style.display = 'none'; document.getElementById('login-screen').style.display = 'flex'; document.getElementById('username').value = ''; document.getElementById('password').value = ''; }