-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
71 lines (64 loc) · 1.86 KB
/
script.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
66
67
68
69
70
71
let dados = [
{
nome: 'Jonas',
senha: '1234',
cargo: 'funcionario'
},
{
nome: 'JonasVas',
senha: '123456',
cargo: 'adm'
}
]
const getDados = (name) => JSON.parse(localStorage.getItem(name)) ?? []
const setDados = (name, obj) => localStorage.setItem(name, JSON.stringify(obj))
setDados('dados', dados)
const resetData = () => {
window.localStorage.clear();
}
const inputFields = document.querySelectorAll('input');
const loginInput = document.getElementById('login');
const passwordInput = document.getElementById('password');
const btnLogin = document.getElementById('btnLogin');
const btnLogout = document.getElementById('btnlogout');
const mainTables = document.getElementsByClassName('container');
const erro = document.getElementById('erro');
inputFields.forEach(function(inputItem){
inputItem.addEventListener('input', function() {
if (passwordInput.value.length > 3 & loginInput.value.length > 3) {
btnLogin.classList.remove('disabled');
} else {
btnLogin.classList.add('disabled');
}
});
});
function validation() {
let flag = false;
for (let i = 0; i < dados.length; i += 1) {
if (loginInput.value === dados[i].nome && passwordInput.value === dados[i].senha){
flag = true;
resetData()
localStorage.setItem('garcom', dados[i].nome);
open('./tables.html', target = '_self')
break;
}
}
if (flag === false){
var e = new Error('Could not parse input');
throw e;
}
};
btnLogin.addEventListener('click', validation);
window.addEventListener('keydown', function (event) {
if (event.defaultPrevented) {
return;
}
switch (event.key) {
case "Enter":
validation();
break;
default:
return;
}
event.preventDefault();
}, true);