feat(auth): mover selector de rol a Iniciar Sesion con campos dinamicos y limpiar registro de padres
This commit is contained in:
+35
-25
@@ -44,31 +44,11 @@
|
|||||||
|
|
||||||
<!-- FORMULARIO 1: INICIAR SESIÓN -->
|
<!-- FORMULARIO 1: INICIAR SESIÓN -->
|
||||||
<form id="formLogin" onsubmit="handleLoginSubmit(event)">
|
<form id="formLogin" onsubmit="handleLoginSubmit(event)">
|
||||||
<div class="login-form-group">
|
|
||||||
<label for="loginUsername">Usuario o Carné:</label>
|
|
||||||
<input type="text" id="loginUsername" class="login-input" placeholder="Ej: admin, padre, mateo, sofia" required autocomplete="username">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="login-form-group">
|
|
||||||
<label for="loginPassword">Contraseña o PIN:</label>
|
|
||||||
<input type="password" id="loginPassword" class="login-input" placeholder="••••••••" required autocomplete="current-password">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="loginErrorMsg" style="display: none; background: #fee2e2; border: 1px solid #fca5a5; color: #991b1b; padding: 8px 12px; border-radius: 10px; font-size: 0.8rem; font-weight: 700; margin-bottom: 12px; text-align: center;"></div>
|
|
||||||
|
|
||||||
<button type="submit" id="btnLoginSubmit" class="login-submit-btn" style="display: flex; align-items: center; justify-content: center; gap: 8px;">
|
|
||||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"/><polyline points="10 17 15 12 10 7"/><line x1="15" x2="3" y1="12" y2="12"/></svg>
|
|
||||||
<span>Iniciar Sesión</span>
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<!-- FORMULARIO 2: REGISTRO DE NUEVOS PADRES -->
|
|
||||||
<form id="formRegisterPadre" onsubmit="handleRegisterPadreSubmit(event)" style="display: none;">
|
|
||||||
<!-- SELECTOR DE ROL: "SOY" CON ICONOS SUPERFINOS Y ELEGANTES (SIN EMOJIS) -->
|
<!-- SELECTOR DE ROL: "SOY" CON ICONOS SUPERFINOS Y ELEGANTES (SIN EMOJIS) -->
|
||||||
<div class="login-role-selector-wrap">
|
<div class="login-role-selector-wrap">
|
||||||
<label style="font-size: 0.74rem; font-weight: 900; color: #475569; text-transform: uppercase; letter-spacing: 0.6px; display: block; margin-bottom: 8px;">Soy</label>
|
<label style="font-size: 0.74rem; font-weight: 900; color: #475569; text-transform: uppercase; letter-spacing: 0.6px; display: block; margin-bottom: 8px;">¿Quién eres?</label>
|
||||||
<div class="login-role-grid">
|
<div class="login-role-grid">
|
||||||
<div onclick="selectRegisterRole('padre')" id="regRoleCardPadre" class="login-role-card selected">
|
<div onclick="selectLoginRole('padre')" id="loginRoleCardPadre" class="login-role-card selected">
|
||||||
<div class="login-role-icon">
|
<div class="login-role-icon">
|
||||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
|
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
|
||||||
<circle cx="9" cy="7" r="3.5"/>
|
<circle cx="9" cy="7" r="3.5"/>
|
||||||
@@ -81,7 +61,7 @@
|
|||||||
<span class="login-role-desc">o Encargado</span>
|
<span class="login-role-desc">o Encargado</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div onclick="selectRegisterRole('estudiante')" id="regRoleCardEstudiante" class="login-role-card">
|
<div onclick="selectLoginRole('estudiante')" id="loginRoleCardEstudiante" class="login-role-card">
|
||||||
<div class="login-role-icon">
|
<div class="login-role-icon">
|
||||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
|
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
|
||||||
<path d="M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1-2.5-2.5Z"/>
|
<path d="M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1-2.5-2.5Z"/>
|
||||||
@@ -94,7 +74,7 @@
|
|||||||
<span class="login-role-desc">Carné QR</span>
|
<span class="login-role-desc">Carné QR</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div onclick="selectRegisterRole('personal')" id="regRoleCardPersonal" class="login-role-card">
|
<div onclick="selectLoginRole('personal')" id="loginRoleCardPersonal" class="login-role-card">
|
||||||
<div class="login-role-icon">
|
<div class="login-role-icon">
|
||||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
|
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
|
||||||
<path d="M6 13.8V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v9.8"/>
|
<path d="M6 13.8V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v9.8"/>
|
||||||
@@ -108,6 +88,36 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="login-form-group">
|
||||||
|
<label id="lblLoginUser" for="loginUsername">Usuario o Teléfono del Padre:</label>
|
||||||
|
<input type="text" id="loginUsername" class="login-input" placeholder="Ej: padre, carlos_papa o 8888-1122" required autocomplete="username">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="login-form-group">
|
||||||
|
<label id="lblLoginPass" for="loginPassword">Contraseña:</label>
|
||||||
|
<input type="password" id="loginPassword" class="login-input" placeholder="••••••••" required autocomplete="current-password">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="loginErrorMsg" style="display: none; background: #fee2e2; border: 1px solid #fca5a5; color: #991b1b; padding: 8px 12px; border-radius: 10px; font-size: 0.8rem; font-weight: 700; margin-bottom: 12px; text-align: center;"></div>
|
||||||
|
|
||||||
|
<button type="submit" id="btnLoginSubmit" class="login-submit-btn" style="display: flex; align-items: center; justify-content: center; gap: 8px;">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"/><polyline points="10 17 15 12 10 7"/><line x1="15" x2="3" y1="12" y2="12"/></svg>
|
||||||
|
<span id="lblBtnLoginText">Ingresar como Padre / Encargado</span>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<!-- FORMULARIO 2: REGISTRO DE NUEVOS PADRES -->
|
||||||
|
<form id="formRegisterPadre" onsubmit="handleRegisterPadreSubmit(event)" style="display: none;">
|
||||||
|
<div style="background: #f0f9ff; border: 1px solid #bae6fd; border-radius: 14px; padding: 12px 14px; margin-bottom: 16px; display: flex; align-items: center; gap: 10px;">
|
||||||
|
<div style="width: 36px; height: 36px; border-radius: 10px; background: #e0f2fe; color: #0284c7; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0;">
|
||||||
|
👨👩👧👦
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<strong style="color: #0369a1; font-size: 0.88rem; display: block;">Registro de Padres o Encargados</strong>
|
||||||
|
<span style="font-size: 0.72rem; color: #64748b;">Crea tu cuenta para vincular a tus hijos y recargarles saldo escolar.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="login-form-group">
|
<div class="login-form-group">
|
||||||
<label for="regNombre">Nombre y Apellidos:</label>
|
<label for="regNombre">Nombre y Apellidos:</label>
|
||||||
<input type="text" id="regNombre" class="login-input" placeholder="Ej: Carlos Alvarado Castro" required autocomplete="name">
|
<input type="text" id="regNombre" class="login-input" placeholder="Ej: Carlos Alvarado Castro" required autocomplete="name">
|
||||||
@@ -137,7 +147,7 @@
|
|||||||
|
|
||||||
<button type="submit" id="btnRegisterSubmit" class="login-submit-btn" style="display: flex; align-items: center; justify-content: center; gap: 8px;">
|
<button type="submit" id="btnRegisterSubmit" class="login-submit-btn" style="display: flex; align-items: center; justify-content: center; gap: 8px;">
|
||||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M19 11v6"/><path d="M22 14h-6"/></svg>
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M19 11v6"/><path d="M22 14h-6"/></svg>
|
||||||
<span>Crear Cuenta y Entrar al Panel</span>
|
<span>Crear Cuenta de Padre y Entrar</span>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
+52
-31
@@ -169,45 +169,51 @@ function switchLoginTab(tab) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let selectedRegisterRole = 'padre';
|
let currentLoginRole = 'padre';
|
||||||
|
|
||||||
function selectRegisterRole(role) {
|
function selectLoginRole(role) {
|
||||||
selectedRegisterRole = role;
|
currentLoginRole = role;
|
||||||
const cardPadre = document.getElementById('regRoleCardPadre');
|
const cardPadre = document.getElementById('loginRoleCardPadre');
|
||||||
const cardEstudiante = document.getElementById('regRoleCardEstudiante');
|
const cardEstudiante = document.getElementById('loginRoleCardEstudiante');
|
||||||
const cardPersonal = document.getElementById('regRoleCardPersonal');
|
const cardPersonal = document.getElementById('loginRoleCardPersonal');
|
||||||
const errorMsg = document.getElementById('registerErrorMsg');
|
|
||||||
|
|
||||||
if (cardPadre) cardPadre.classList.toggle('selected', role === 'padre');
|
if (cardPadre) cardPadre.classList.toggle('selected', role === 'padre');
|
||||||
if (cardEstudiante) cardEstudiante.classList.toggle('selected', role === 'estudiante');
|
if (cardEstudiante) cardEstudiante.classList.toggle('selected', role === 'estudiante');
|
||||||
if (cardPersonal) cardPersonal.classList.toggle('selected', role === 'personal');
|
if (cardPersonal) cardPersonal.classList.toggle('selected', role === 'personal');
|
||||||
|
|
||||||
if (window.sounds) window.sounds.playTap();
|
const lblUser = document.getElementById('lblLoginUser');
|
||||||
|
const inputUser = document.getElementById('loginUsername');
|
||||||
|
const lblPass = document.getElementById('lblLoginPass');
|
||||||
|
const inputPass = document.getElementById('loginPassword');
|
||||||
|
const btnText = document.getElementById('lblBtnLoginText');
|
||||||
|
|
||||||
if (role === 'estudiante') {
|
if (role === 'estudiante') {
|
||||||
if (errorMsg) {
|
if (lblUser) lblUser.textContent = 'Carné o Código de Estudiante:';
|
||||||
errorMsg.style.background = '#eff6ff';
|
if (inputUser) inputUser.placeholder = 'Ej: EST-2026-00001, mateo, sofia';
|
||||||
errorMsg.style.borderColor = '#93c5fd';
|
if (lblPass) lblPass.textContent = 'PIN Escolar (4 dígitos) o Contraseña:';
|
||||||
errorMsg.style.color = '#1e40af';
|
if (inputPass) inputPass.placeholder = 'Ej: 1234';
|
||||||
errorMsg.innerHTML = '<strong>🎒 Cuenta de Estudiante:</strong> Tu carné y código QR son entregados directamente por el centro educativo. Si ya cuentas con carné o credenciales, toca en <a href="#" onclick="switchLoginTab(\'login\'); return false;" style="color: #0284c7; font-weight: 800; text-decoration: underline;">Iniciar Sesión</a>.';
|
if (btnText) btnText.textContent = 'Ingresar como Estudiante';
|
||||||
errorMsg.style.display = 'block';
|
|
||||||
}
|
|
||||||
} else if (role === 'personal') {
|
} else if (role === 'personal') {
|
||||||
if (errorMsg) {
|
if (lblUser) lblUser.textContent = 'Usuario de Soda o Admin:';
|
||||||
errorMsg.style.background = '#fefce8';
|
if (inputUser) inputUser.placeholder = 'Ej: admin, cajero, soda';
|
||||||
errorMsg.style.borderColor = '#fde047';
|
if (lblPass) lblPass.textContent = 'Contraseña:';
|
||||||
errorMsg.style.color = '#854d0e';
|
if (inputPass) inputPass.placeholder = '••••••••';
|
||||||
errorMsg.innerHTML = '<strong>👨🍳 Personal de Soda:</strong> Las credenciales de punto de venta y administración son asignadas por la dirección escolar. Por favor ingresa en <a href="#" onclick="switchLoginTab(\'login\'); return false;" style="color: #0284c7; font-weight: 800; text-decoration: underline;">Iniciar Sesión</a>.';
|
if (btnText) btnText.textContent = 'Ingresar al Sistema de Soda';
|
||||||
errorMsg.style.display = 'block';
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (errorMsg) {
|
// Padre / Encargado
|
||||||
errorMsg.style.display = 'none';
|
if (lblUser) lblUser.textContent = 'Usuario o Teléfono del Padre:';
|
||||||
errorMsg.style.background = '#fee2e2';
|
if (inputUser) inputUser.placeholder = 'Ej: padre, carlos_papa o 8888-1122';
|
||||||
errorMsg.style.borderColor = '#fca5a5';
|
if (lblPass) lblPass.textContent = 'Contraseña:';
|
||||||
errorMsg.style.color = '#991b1b';
|
if (inputPass) inputPass.placeholder = '••••••••';
|
||||||
|
if (btnText) btnText.textContent = 'Ingresar como Padre / Encargado';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (window.sounds) window.sounds.playTap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compatibilidad
|
||||||
|
function selectRegisterRole(role) {
|
||||||
|
selectLoginRole(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleRegisterPadreSubmit(event) {
|
async function handleRegisterPadreSubmit(event) {
|
||||||
@@ -251,13 +257,23 @@ async function handleRegisterPadreSubmit(event) {
|
|||||||
if (window.sounds) window.sounds.playError();
|
if (window.sounds) window.sounds.playError();
|
||||||
} finally {
|
} finally {
|
||||||
btnSubmit.disabled = false;
|
btnSubmit.disabled = false;
|
||||||
btnSubmit.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" style="margin-right:6px;"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M19 11v6"/><path d="M22 14h-6"/></svg> Crear Cuenta y Entrar al Panel';
|
btnSubmit.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" style="margin-right:6px;"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M19 11v6"/><path d="M22 14h-6"/></svg> Crear Cuenta de Padre y Entrar';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function quickFillLogin(username, password) {
|
function quickFillLogin(username, password) {
|
||||||
document.getElementById('loginUsername').value = username;
|
if (username === 'mateo' || username === 'sofia') {
|
||||||
document.getElementById('loginPassword').value = password;
|
selectLoginRole('estudiante');
|
||||||
|
} else if (username === 'admin' || username === 'cajero' || username === 'dev') {
|
||||||
|
selectLoginRole('personal');
|
||||||
|
} else if (username === 'padre') {
|
||||||
|
selectLoginRole('padre');
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputUser = document.getElementById('loginUsername');
|
||||||
|
const inputPass = document.getElementById('loginPassword');
|
||||||
|
if (inputUser) inputUser.value = username;
|
||||||
|
if (inputPass) inputPass.value = password;
|
||||||
handleLoginSubmit();
|
handleLoginSubmit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +325,12 @@ async function handleLoginSubmit(event) {
|
|||||||
if (window.sounds) window.sounds.playError();
|
if (window.sounds) window.sounds.playError();
|
||||||
} finally {
|
} finally {
|
||||||
submitBtn.disabled = false;
|
submitBtn.disabled = false;
|
||||||
submitBtn.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" style="margin-right:6px;"><path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"/><polyline points="10 17 15 12 10 7"/><line x1="15" x2="3" y1="12" y2="12"/></svg> Iniciar Sesión';
|
const btnLabel = currentLoginRole === 'estudiante'
|
||||||
|
? 'Ingresar como Estudiante'
|
||||||
|
: currentLoginRole === 'personal'
|
||||||
|
? 'Ingresar al Sistema de Soda'
|
||||||
|
: 'Ingresar como Padre / Encargado';
|
||||||
|
submitBtn.innerHTML = `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" style="margin-right:6px;"><path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"/><polyline points="10 17 15 12 10 7"/><line x1="15" x2="3" y1="12" y2="12"/></svg> <span id="lblBtnLoginText">${btnLabel}</span>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user