-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
55 lines (47 loc) · 1.79 KB
/
Copy pathscript.js
File metadata and controls
55 lines (47 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function mostrarSeccion(id) {
const secciones = ['bienvenida', 'nosotros', 'contacto', 'juego', 'iniciar_sesion', 'registrar'];
secciones.forEach(sec => {
document.getElementById(sec).classList.add('hidden');
});
document.getElementById(id).classList.remove('hidden');
}
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('loginForm');
form.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(this);
const data = {
email: formData.get('email'),
password: formData.get('password')
};
fetch('http://localhost/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(res => res.json())
.then(res => {
if (res.userId) {
console.log('Login OK, userId:', res.userId);
const comprarJuego = document.getElementById('comprarJuego');
const agregarJuego = document.getElementById('agregarJuego');
const editIcon = document.getElementById('editIcon');
const addFAQ = document.getElementById('addFAQ');
const uploadPhoto = document.getElementById('uploadPhoto');
comprarJuego.style.display = 'none';
agregarJuego.style.display = 'flex';
editIcon.style.display = 'flex';
addFAQ.style.display = 'flex';
uploadPhoto.style.display = 'flex';
} else {
alert('Usuario o contraseña incorrectos');
}
})
.catch(err => {
console.error('Error en login:', err);
alert('Error al conectar con el servidor');
});
});
});