feat(auth): agregar modal de selección de registro Padre vs Alumno con banners y roles dedicados
This commit is contained in:
+71
-8
@@ -131,9 +131,74 @@
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<!-- CONTENIDO 2: REGISTRO DE CUENTA -->
|
||||
<!-- CONTENIDO 2: MODAL DE SELECCIÓN DE TIPO DE REGISTRO -->
|
||||
<div id="sheetContentRegisterChoose" style="display: none; padding: 4px 0 8px;">
|
||||
<div style="text-align: center; margin-bottom: 18px;">
|
||||
<h4 style="margin: 0 0 6px; font-size: 1.15rem; font-weight: 800; color: #0f172a;">¿Cómo deseas registrarte?</h4>
|
||||
<p style="margin: 0; font-size: 0.82rem; color: #64748b;">Elige tu perfil para continuar con el registro</p>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px;">
|
||||
<!-- BOTÓN 1: PADRE DE FAMILIA -->
|
||||
<button type="button" onclick="selectRegisterType('padre')" style="display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 16px; border: 2px solid #bae6fd; background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%); cursor: pointer; text-align: left; transition: all 0.2s ease; box-shadow: 0 2px 8px rgba(2, 132, 199, 0.08); width: 100%;">
|
||||
<div style="width: 48px; height: 48px; border-radius: 12px; background: white; border: 1.5px solid #7dd3fc; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; flex-shrink: 0; box-shadow: 0 2px 6px rgba(0,0,0,0.04);">
|
||||
👨👩👧
|
||||
</div>
|
||||
<div style="flex: 1;">
|
||||
<strong style="display: block; font-size: 1rem; font-weight: 800; color: #0369a1; margin-bottom: 2px;">Padre de familia</strong>
|
||||
<span style="display: block; font-size: 0.76rem; color: #475569; line-height: 1.35;">Crea tu cuenta para vincular a tus hijos y recargarles saldo en SINPE Móvil.</span>
|
||||
</div>
|
||||
<div style="color: #0284c7; font-weight: 800; font-size: 1.3rem;">›</div>
|
||||
</button>
|
||||
|
||||
<!-- BOTÓN 2: ALUMNO GENERAL -->
|
||||
<button type="button" onclick="selectRegisterType('alumno')" style="display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 16px; border: 2px solid #e2e8f0; background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%); cursor: pointer; text-align: left; transition: all 0.2s ease; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04); width: 100%;">
|
||||
<div style="width: 48px; height: 48px; border-radius: 12px; background: #f1f5f9; border: 1.5px solid #cbd5e1; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; flex-shrink: 0;">
|
||||
🎓
|
||||
</div>
|
||||
<div style="flex: 1;">
|
||||
<strong style="display: block; font-size: 1rem; font-weight: 800; color: #1e293b; margin-bottom: 2px;">Alumno general</strong>
|
||||
<span style="display: block; font-size: 0.76rem; color: #64748b; line-height: 1.35;">Para estudiantes y compras personales en la soda estudiantil.</span>
|
||||
</div>
|
||||
<div style="color: #94a3b8; font-weight: 800; font-size: 1.3rem;">›</div>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div style="text-align: center; border-top: 1px solid #f1f5f9; padding-top: 14px;">
|
||||
<p style="font-size: 0.82rem; color: #64748b; margin: 0;">
|
||||
¿Ya tienes cuenta registrada?
|
||||
<button type="button" onclick="switchSheetView('login')" style="background: none; border: none; color: #0284c7; font-weight: 800; cursor: pointer; text-decoration: underline; font-size: 0.82rem; padding: 0;">Inicia sesión aquí</button>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CONTENIDO 2.1: FORMULARIO DE REGISTRO (PADRE O ALUMNO) -->
|
||||
<div id="sheetContentRegister" style="display: none;">
|
||||
<!-- BANNER PADRE (visible solo para rol padre) -->
|
||||
<div id="bannerPadreRegister" style="background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%); border: 1.5px solid #bae6fd; border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; display: flex; align-items: center; gap: 10px;">
|
||||
<div style="width: 36px; height: 36px; border-radius: 10px; background: white; border: 1px solid #bae6fd; display: flex; align-items: center; justify-content: center; flex-shrink: 0; padding: 4px;">
|
||||
<img src="/img/sibopay-emblem.png" alt="SiboPay" style="width: 100%; height: 100%; object-fit: contain;">
|
||||
</div>
|
||||
<div>
|
||||
<strong style="color: #0369a1; font-size: 0.86rem; display: block; font-weight: 800;">Registro de Padres o Encargados</strong>
|
||||
<span style="font-size: 0.72rem; color: #475569; display: block;">Crea tu cuenta para vincular a tus hijos y recargarles saldo con SINPE móvil.</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- BANNER ALUMNO (visible solo para rol alumno) -->
|
||||
<div id="bannerAlumnoRegister" style="display: none; background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%); border: 1.5px solid #e2e8f0; border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; align-items: center; gap: 10px;">
|
||||
<div style="width: 36px; height: 36px; border-radius: 10px; background: white; border: 1px solid #cbd5e1; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 1.25rem;">
|
||||
🎓
|
||||
</div>
|
||||
<div>
|
||||
<strong style="color: #1e293b; font-size: 0.86rem; display: block; font-weight: 800;">Registro de Alumno General</strong>
|
||||
<span style="font-size: 0.72rem; color: #64748b; display: block;">Crea tu cuenta personal para acceder a tu carné y monedero digital.</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form id="formRegisterPadre" onsubmit="handleRegisterPadreSubmit(event)">
|
||||
<input type="hidden" id="regTargetRol" value="padre">
|
||||
|
||||
<div class="login-form-group">
|
||||
<label for="regNombre">Nombre y Apellidos:</label>
|
||||
<input type="text" id="regNombre" class="login-input" placeholder="Ej: Carlos Alvarado Castro" required autocomplete="name">
|
||||
@@ -168,15 +233,13 @@
|
||||
|
||||
<button type="submit" id="btnRegisterSubmit" class="login-submit-btn" style="display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 48px; border-radius: 12px; font-weight: 800; font-size: 1rem; background: linear-gradient(135deg, #0284c7, #0369a1); color: white; border: none; cursor: pointer; box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="9" cy="7" r="3.5"/><path d="M3 20v-1.5A4.5 4.5 0 0 1 7.5 14h3A4.5 4.5 0 0 1 15 18.5V20"/><circle cx="17.5" cy="7.5" r="2.5"/><path d="M15 14a3.5 3.5 0 0 1 5.5 3v3"/></svg>
|
||||
<span>Crear Cuenta y Entrar</span>
|
||||
<span id="lblBtnRegisterSubmit">Crear Cuenta y Entrar</span>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div style="text-align: center; margin-top: 14px;">
|
||||
<p style="font-size: 0.82rem; color: #64748b; margin: 0;">
|
||||
¿Ya tienes cuenta registrada?
|
||||
<button type="button" onclick="switchSheetView('login')" style="background: none; border: none; color: #0284c7; font-weight: 800; cursor: pointer; text-decoration: underline; font-size: 0.82rem; padding: 0;">Inicia sesión aquí</button>
|
||||
</p>
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-top: 14px; font-size: 0.82rem;">
|
||||
<button type="button" onclick="switchSheetView('register-choose')" style="background: none; border: none; color: #0284c7; font-weight: 700; cursor: pointer; text-decoration: underline; padding: 0;">← Cambiar tipo de cuenta</button>
|
||||
<button type="button" onclick="switchSheetView('login')" style="background: none; border: none; color: #64748b; font-weight: 700; cursor: pointer; text-decoration: underline; padding: 0;">Iniciar sesión</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5417,6 +5480,6 @@
|
||||
<script src="/js/sounds.js?v=19.4"></script>
|
||||
<script src="/js/jsQR.js" defer></script>
|
||||
<script src="/js/food-icons.js?v=19.4" defer></script>
|
||||
<script src="/js/app.js?v=20.6"></script>
|
||||
<script src="/js/app.js?v=20.7"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+42
-4
@@ -331,17 +331,21 @@ function closeLoginSheet(e) {
|
||||
|
||||
function switchSheetView(view) {
|
||||
const loginContent = document.getElementById('sheetContentLogin');
|
||||
const registerChooseContent = document.getElementById('sheetContentRegisterChoose');
|
||||
const registerContent = document.getElementById('sheetContentRegister');
|
||||
const forgotContent = document.getElementById('sheetContentForgot');
|
||||
const title = document.getElementById('bottomSheetTitle');
|
||||
|
||||
if (loginContent) loginContent.style.display = 'none';
|
||||
if (registerChooseContent) registerChooseContent.style.display = 'none';
|
||||
if (registerContent) registerContent.style.display = 'none';
|
||||
if (forgotContent) forgotContent.style.display = 'none';
|
||||
|
||||
if (view === 'register') {
|
||||
if (registerContent) registerContent.style.display = 'block';
|
||||
if (view === 'register' || view === 'register-choose') {
|
||||
if (registerChooseContent) registerChooseContent.style.display = 'block';
|
||||
if (title) title.textContent = 'Crear Cuenta';
|
||||
} else if (view === 'register-form') {
|
||||
if (registerContent) registerContent.style.display = 'block';
|
||||
} else if (view === 'forgot') {
|
||||
if (forgotContent) forgotContent.style.display = 'block';
|
||||
if (title) title.textContent = 'Restablecer Contraseña';
|
||||
@@ -359,6 +363,30 @@ function switchSheetView(view) {
|
||||
}
|
||||
}
|
||||
|
||||
function selectRegisterType(type) {
|
||||
const bannerPadre = document.getElementById('bannerPadreRegister');
|
||||
const bannerAlumno = document.getElementById('bannerAlumnoRegister');
|
||||
const rolInput = document.getElementById('regTargetRol');
|
||||
const title = document.getElementById('bottomSheetTitle');
|
||||
const btnLabel = document.getElementById('lblBtnRegisterSubmit');
|
||||
|
||||
if (rolInput) rolInput.value = type;
|
||||
|
||||
if (type === 'padre') {
|
||||
if (bannerPadre) bannerPadre.style.display = 'flex';
|
||||
if (bannerAlumno) bannerAlumno.style.display = 'none';
|
||||
if (title) title.textContent = 'Registro de Padres';
|
||||
if (btnLabel) btnLabel.textContent = 'Crear Cuenta de Padre y Entrar';
|
||||
} else {
|
||||
if (bannerPadre) bannerPadre.style.display = 'none';
|
||||
if (bannerAlumno) bannerAlumno.style.display = 'flex';
|
||||
if (title) title.textContent = 'Registro de Alumno';
|
||||
if (btnLabel) btnLabel.textContent = 'Crear Cuenta de Alumno y Entrar';
|
||||
}
|
||||
|
||||
switchSheetView('register-form');
|
||||
}
|
||||
|
||||
function openTerminosModal() {
|
||||
window.open('/terminos', '_blank');
|
||||
}
|
||||
@@ -428,6 +456,8 @@ async function handleRegisterPadreSubmit(event) {
|
||||
const email = emailInput ? emailInput.value.trim() : '';
|
||||
const username = document.getElementById('regUsername').value.trim();
|
||||
const password = document.getElementById('regPassword').value.trim();
|
||||
const rolInput = document.getElementById('regTargetRol');
|
||||
const rol = (rolInput && rolInput.value === 'alumno') ? 'estudiante' : 'padre';
|
||||
const errorMsg = document.getElementById('registerErrorMsg');
|
||||
const btnSubmit = document.getElementById('btnRegisterSubmit');
|
||||
|
||||
@@ -456,7 +486,7 @@ async function handleRegisterPadreSubmit(event) {
|
||||
const res = await fetch('/api/auth/register-padre', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ nombre, fecha_nacimiento, telefono, email, username, password })
|
||||
body: JSON.stringify({ nombre, fecha_nacimiento, telefono, email, username, password, rol })
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Error al registrar la cuenta');
|
||||
@@ -465,15 +495,23 @@ async function handleRegisterPadreSubmit(event) {
|
||||
...data.user,
|
||||
hijos: []
|
||||
};
|
||||
if (data.estudiante) {
|
||||
currentStudent = data.estudiante;
|
||||
safeSetItem('recreopay_estudiante', JSON.stringify(data.estudiante));
|
||||
}
|
||||
try {
|
||||
safeSetItem('sibopay_user', JSON.stringify(currentUser));
|
||||
safeSetItem('recreopay_user', JSON.stringify(currentUser));
|
||||
} catch (_) {}
|
||||
|
||||
const welcomeMsg = (data.user.rol === 'padre')
|
||||
? `Hola ${data.user.nombre}, tu cuenta de padre fue creada exitosamente.\n\nYa puedes vincular a tus hijos y recargarles saldo con SINPE Móvil.`
|
||||
: `Hola ${data.user.nombre}, tu cuenta de estudiante fue creada exitosamente.\n\nYa puedes acceder a tu carné digital y tus compras en la soda.`;
|
||||
|
||||
if (window.sounds) window.sounds.playSuccess();
|
||||
await showAppAlert({
|
||||
title: '¡Bienvenido(a) a SiboPay!',
|
||||
message: `Hola ${data.user.nombre}, tu cuenta fue creada exitosamente.\n\nYa puedes acceder a todos los servicios y monedero digital SiboPay.`,
|
||||
message: welcomeMsg,
|
||||
type: 'success',
|
||||
confirmText: 'Entrar a mi Panel'
|
||||
});
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
// SiboPay PWA Service Worker v20.6 - Ultra Fast Startup & Stale-While-Revalidate
|
||||
const CACHE_NAME = 'sibopay-v20.6';
|
||||
// SiboPay PWA Service Worker v20.7 - Ultra Fast Startup & Stale-While-Revalidate
|
||||
const CACHE_NAME = 'sibopay-v20.7';
|
||||
const STATIC_ASSETS = [
|
||||
'/',
|
||||
'/index.html',
|
||||
@@ -11,7 +11,7 @@ const STATIC_ASSETS = [
|
||||
'/css/styles.css?v=19.9',
|
||||
'/css/desktop.css?v=2.2',
|
||||
'/js/dialogs.js?v=19.4',
|
||||
'/js/app.js?v=20.6',
|
||||
'/js/app.js?v=20.7',
|
||||
'/js/pos.js?v=20.5',
|
||||
'/js/sounds.js?v=19.4',
|
||||
'/js/food-icons.js?v=19.4',
|
||||
|
||||
+24
-5
@@ -534,10 +534,10 @@ app.post('/api/auth/login', (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Registro de nuevos usuarios desde la pantalla de bienvenida
|
||||
// Registro de nuevos usuarios (Padres o Alumnos) desde la pantalla de bienvenida
|
||||
app.post('/api/auth/register-padre', (req, res) => {
|
||||
try {
|
||||
const { nombre, telefono, email, username, password, fecha_nacimiento } = req.body;
|
||||
const { nombre, telefono, email, username, password, fecha_nacimiento, rol } = req.body;
|
||||
if (!nombre || !username || !password || !email) {
|
||||
return res.status(400).json({ error: 'Nombre completo, correo electrónico, usuario y contraseña son requeridos' });
|
||||
}
|
||||
@@ -548,6 +548,7 @@ app.post('/api/auth/register-padre', (req, res) => {
|
||||
const cleanTel = telefono ? String(telefono).trim() : '';
|
||||
const cleanEmail = String(email).trim().toLowerCase();
|
||||
const cleanFechaNac = fecha_nacimiento ? String(fecha_nacimiento).trim() : '';
|
||||
const targetRol = (rol === 'estudiante' || rol === 'alumno') ? 'estudiante' : 'padre';
|
||||
|
||||
if (cleanUser.length < 3) {
|
||||
return res.status(400).json({ error: 'El nombre de usuario debe tener al menos 3 caracteres' });
|
||||
@@ -573,23 +574,41 @@ app.post('/api/auth/register-padre', (req, res) => {
|
||||
|
||||
const insert = db.prepare(`
|
||||
INSERT INTO usuarios (username, password_hash, rol, nombre, telefono, email, fecha_nacimiento)
|
||||
VALUES (?, ?, 'padre', ?, ?, ?, ?)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
`);
|
||||
const result = insert.run(cleanUser, cleanPass, cleanNombre, cleanTel, cleanEmail, cleanFechaNac);
|
||||
const result = insert.run(cleanUser, cleanPass, targetRol, cleanNombre, cleanTel, cleanEmail, cleanFechaNac);
|
||||
|
||||
const newUser = {
|
||||
id: result.lastInsertRowid,
|
||||
username: cleanUser,
|
||||
rol: 'padre',
|
||||
rol: targetRol,
|
||||
nombre: cleanNombre,
|
||||
telefono: cleanTel,
|
||||
email: cleanEmail,
|
||||
fecha_nacimiento: cleanFechaNac
|
||||
};
|
||||
|
||||
let estudiante = null;
|
||||
if (targetRol === 'estudiante') {
|
||||
try {
|
||||
const codEst = `EST-${Date.now().toString().slice(-6)}`;
|
||||
const qrToken = `QR-${Date.now()}-${Math.random().toString(36).substring(2, 7).toUpperCase()}`;
|
||||
const resEst = db.prepare(`
|
||||
INSERT INTO estudiantes
|
||||
(usuario_id, codigo_estudiante, nombre_completo, edad, grado, seccion, qr_token, pin_seguridad, foto_url, saldo_colones, limite_diario_colones, alergias, padre_nombre, padre_telefono, permitir_transferencias, tarjeta_bloqueada, activo, escuela_id)
|
||||
VALUES (?, ?, ?, 12, 'General', '1', ?, ?, NULL, 0, 3000, 'Ninguna conocida', '', '', 1, 0, 1, 1)
|
||||
`).run(newUser.id, codEst, cleanNombre, qrToken, cleanPass.slice(0, 4));
|
||||
|
||||
estudiante = db.prepare('SELECT * FROM estudiantes WHERE id = ?').get(resEst.lastInsertRowid);
|
||||
} catch (errEst) {
|
||||
console.warn('[AUTH] Error al crear ficha de estudiante automática:', errEst);
|
||||
}
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
user: newUser,
|
||||
estudiante: estudiante,
|
||||
hijos: []
|
||||
});
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user