Skip to content
Snippets Groups Projects
Commit 9753917a authored by Jesus Galaz's avatar Jesus Galaz
Browse files

Changing comments to english

parent b91fd978
No related branches found
No related tags found
1 merge request!5User authentication implemented
Pipeline #15677 passed
......@@ -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>
......
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) => {
......
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' });
......
......@@ -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' });
});
});
......
......@@ -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) {
......
......@@ -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}`));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment