diff --git a/public/index.html b/public/index.html index ceb9136c16aa6ce2751a96e7907124cc9fa7cbf3..ca170f1c94da69385f6698bfa665cb123e73c96c 100644 --- a/public/index.html +++ b/public/index.html @@ -25,7 +25,7 @@ <button type="submit">Add</button> </form> - <!-- Lista de tareas --> + <!-- Todo List --> <section class="task-list"> <ul id="task-list"></ul> </section> diff --git a/public/js/auth.js b/public/js/auth.js index 0911918688e44fa3fec7d0708986a27bf6a24fed..2013da931bca405b3eccf2ace9ba0d7ac674df93 100644 --- a/public/js/auth.js +++ b/public/js/auth.js @@ -1,5 +1,6 @@ document.addEventListener('DOMContentLoaded', () => { - // Registro + + // Register const registerForm = document.getElementById('register-form'); if (registerForm) { registerForm.addEventListener('submit', async (event) => { @@ -36,7 +37,7 @@ document.addEventListener('DOMContentLoaded', () => { }); } - // Inicio de sesión + // Login In const loginForm = document.getElementById('login-form'); if (loginForm) { loginForm.addEventListener('submit', async (event) => { diff --git a/public/js/index.js b/public/js/index.js index ad7a7337b904f4a0168684e808990d5f219aec34..5d8064574ffe7b926ddbcceae836114e138a021f 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1,7 +1,7 @@ document.addEventListener('DOMContentLoaded', async () => { const logoutBtn = document.getElementById('logout-btn'); - // Evento para el botón de logout + // Event for the logout button logoutBtn.addEventListener('click', async () => { try { const res = await fetch('/api/users/logout', { method: 'POST' }); diff --git a/routes/todos.js b/routes/todos.js index fb0286b6359e2e24a78e4e1be0a18fed2fa15857..8154cf9113a0a9ffa824114ea20067481d3df3eb 100644 --- a/routes/todos.js +++ b/routes/todos.js @@ -2,7 +2,7 @@ const express = require('express'); const router = express.Router(); const Todo = require('../models/todo'); -// Middleware para verificar si el usuario está autenticado +// Middleware to verify if the user is authenticated function isAuthenticated(req, res, next) { if (req.session.user) { return next(); @@ -18,7 +18,6 @@ router.post('/logout', (req, res) => { console.error('Error al destruir la sesión:', err); return res.status(500).json({ error: 'Error al cerrar sesión' }); } - // Redirigir al cliente o enviar una respuesta exitosa res.status(200).json({ message: 'Logout successful' }); }); }); diff --git a/routes/users.js b/routes/users.js index cf9fc0443b184090e80bd939a586724bb2af1e8b..13da3ede5d57415fd6a474d353b623482b5b0a2a 100644 --- a/routes/users.js +++ b/routes/users.js @@ -8,16 +8,16 @@ router.post('/register', async (req, res) => { const { username, password } = req.body; try { - // Verificar si el usuario ya existe + // Verify if the user exists const existingUser = await User.findOne({ username }); if (existingUser) { return res.status(400).json({ error: 'User already exists' }); } - // Encriptar la contraseña antes de guardarla + // Encrypt the password const hashedPassword = await bcrypt.hash(password, 10); - // Crear un nuevo usuario con la contraseña encriptada + // Creating a new user with the encrypted password const user = new User({ username, password: hashedPassword }); await user.save(); @@ -59,7 +59,7 @@ router.post('/login', async (req, res) => { }); -// Cerrar sesión del usuario +// Closing user session router.post('/logout', (req, res) => { req.session.destroy(err => { if (err) { diff --git a/server.js b/server.js index 96ecccafc5b2bc0590fcdcf7cdb25affe49c28fd..8dc73f18130077caa361219022688b47c55e8c21 100644 --- a/server.js +++ b/server.js @@ -9,7 +9,7 @@ const app = express(); app.use(express.json()); app.use(express.static(path.join(__dirname, 'public'))); -// Configuración de la sesión +// Session configuration app.use( session({ secret: 'session_secret', @@ -19,13 +19,13 @@ app.use( }) ); -// Conectar a MongoDB +// Connection to MongoDB connectDB(); -// Rutas +// Routes app.use('/api/todos', require('./routes/todos')); app.use('/api/users', require('./routes/users')); -// Iniciar el servidor +// Initialize the server const PORT = process.env.PORT || 3000; app.listen(PORT, () => console.log(`Server running on port ${PORT}`));