Cambios de parametros en registro de usuarios para el idioma

This commit is contained in:
JorgeLuisOZ 2025-06-03 22:41:58 -06:00
parent 5862c37c70
commit 96f7b057b0
5 changed files with 96 additions and 19 deletions

View File

@ -1,13 +1,68 @@
/* Fondo general */
body {
background: linear-gradient(to right, #6dd5fa, #2980b9);
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.card {
width: 100%;
max-width: 420px;
border-radius: 1rem;
box-shadow: 0 0 20px rgba(0,0,0,0.2);
}
background: linear-gradient(to bottom right, #e0f7fa, #f1f8ff);
font-family: 'Segoe UI', sans-serif;
}
/* Tarjeta del login */
.card {
border-radius: 20px;
border: none;
background-color: #ffffffee;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}
/* Título principal */
.card h3 {
font-weight: bold;
color: #0077b6;
}
/* Input y botones */
.form-control {
border-radius: 12px;
border: 1px solid #b0bec5;
}
.form-control:focus {
border-color: #00bcd4;
box-shadow: 0 0 0 0.15rem rgba(0, 188, 212, 0.25);
}
.btn-primary {
background-color: #0077b6;
border: none;
border-radius: 12px;
transition: background-color 0.3s ease;
}
.btn-primary:hover {
background-color: #005f8c;
}
/* Idioma + Enlace de registro */
.text-center small {
font-size: 0.85rem;
color: #37474f;
}
a {
color: #0077b6;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* Select de idioma */
#languageSelect {
border-radius: 999px;
background-color: #ffffff;
padding: 2px 10px;
font-size: 0.85rem;
min-width: 90px; /* 👈 da espacio para el texto */
padding-right: 24px; /* 👈 da espacio para la flechita */
background-clip: padding-box; /* asegura que no se solape */
}

View File

@ -6,6 +6,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet">
<link rel="stylesheet" href="css/login.css">
</head>
<body class="bg-light">
@ -23,8 +26,16 @@
</div>
<button type="submit" class="btn btn-primary w-100">Ingresar</button>
</form>
<div class="text-center mt-3">
<div class="text-center mt-3 d-flex justify-content-between align-items-center">
<small>¿No tienes cuenta? <a href="register.html">Regístrate aquí</a></small>
<div class="d-flex align-items-center ms-4"> <!-- ms-4 para separar del texto -->
<i class="bi bi-globe me-0"></i> <!-- me-0 para pegar el ícono al select -->
<select class="form-select form-select-sm border-0 shadow-none" id="languageSelect" style="width: auto;">
<option value="es">Español</option>
<option value="en">English</option>
<option value="fr">Français</option>
</select>
</div>
</div>
</div>
</div>

View File

@ -36,6 +36,14 @@
<option value="athlete">Atleta</option>
</select>
</div>
<div class="mb-3">
<label for="language" class="form-label">Idioma</label>
<select class="form-select" id="language" name="language" required>
<option value="es">Español</option>
<option value="en">Inglés</option>
<option value="fr">Francés</option>
</select>
</div>
<button type="submit" class="btn btn-success w-100">Registrarse</button>
</form>
<div class="text-center mt-3">

View File

@ -18,6 +18,7 @@ const userSchema = new mongoose.Schema({
email: { type: String, unique: true, required: true },
passwordHash: String,
role: { type: String, enum: ['coach', 'athlete'], required: true },
language: { type: String, default: 'es' }, // <- CAMPO AÑADIDO
createdAt: { type: Date, default: Date.now }
});
@ -25,14 +26,14 @@ const User = mongoose.model('User', userSchema);
// === Ruta: Registro de usuario ===
router.post('/register', async (req, res) => {
const { name, username, email, password, role } = req.body;
const { name, username, email, password, role, language } = req.body;
try {
const existing = await User.findOne({ email });
if (existing) return res.status(400).send('Correo ya registrado');
const passwordHash = await bcrypt.hash(password, 10);
const user = new User({ name, username, email, passwordHash, role });
const user = new User({ name, username, email, passwordHash, role, language });
await user.save();
res.redirect('/index.html');
@ -56,7 +57,8 @@ router.post('/login', async (req, res) => {
res.json({
userId: user._id,
name: user.name,
role: user.role
role: user.role,
language: user.language // <- También puedes enviar este dato al frontend
});
} catch (error) {
console.error('Error en login:', error);
@ -64,6 +66,4 @@ router.post('/login', async (req, res) => {
}
});
module.exports = router;

View File

@ -29,7 +29,10 @@ router.get('/:id', async (req, res) => {
await client.connect();
const db = client.db('swimartdb');
const user = await db.collection('users')
.findOne({ _id: new ObjectId(req.params.id) }, { projection: { name: 1, email: 1, role: 1 } });
.findOne(
{ _id: new ObjectId(req.params.id) },
{ projection: { name: 1, email: 1, role: 1, language: 1 } } // ← aquí se añade
);
if (!user) {
return res.status(404).json({ error: 'Usuario no encontrado' });