-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogar.js
65 lines (45 loc) · 2.34 KB
/
logar.js
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
56
57
58
59
60
61
62
63
64
65
const btn = document.querySelector('button');
btn.addEventListener('click', function(){
alert("E-mail ou senha inválido");
});
function carregarUsuario(){
return fetch("http://localhost:3000/senhas").then(resposta => { // troquei essa url, antes era http://localhost:3000/usuarios?email=${email}
if(resposta.ok && resposta.status === 200) {
return resposta.json();
}
} ). catch(erro => {
console.log(`Erro ao carregar os usuários. ${erro}`);
})
}
function validate() {
let email = document.getElementById("email").value;
let senha = document.getElementById("senha").value;
let logged = false;
/* GET /posts?title=json-server&author=typicode
GET /posts?id=1&id=2
GET /comments?author.name=typicode*/
carregarUsuario().then(usuario => {
console.log(usuario);
if (usuario.email == email && usuario.senha == senha) {
document.getElementById("form").action = "/src/paginas/video.html";
document.getElementById("form").submit();
} else {
document.getElementById("form").action = "/src/paginas/logar.html";
document.getElementById('msg').innerHTML = `Usuário/senha inválidos `;
};
})
/* fetch(`http://localhost:3000/usuarios?email=${email}`).then(resposta => {
if (resposta.ok && resposta.status == 200) {
const usuario = resposta.json();
usuario.then(console.log);
if (usuario.email == email && usuario.senha == senha) {
document.getElementById("form").action = "/src/paginas/video.html";
document.getElementById("form").submit();
} else {
document.getElementById("form").action = "/src/paginas/logar.html";
document.getElementById('msg').innerHTML = `Usuário/senha inválidos `;
};
}
}) */
// const carregarVideos = () => { return fetch("http://localhost:3000/videos").then(resposta => { if (resposta.ok && resposta.status === 200) { return resposta.json(); } if (resposta.status === 404) { mostrarMensagem("mensagem", "Nenhum video encontrado.", "info"); } }).catch(erro => { console.log(`Erro ao carregar os videos. ${erro}`); mostrarMensagem("mensagem", "Não foi possível carregar os feedbacks. Tente mais tarde.", "alerta"); }) }
}