-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
93 lines (73 loc) · 2.18 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const form = document.getElementById("form1");
const email = document.getElementById("email");
const password = document.getElementById("password");
const form2 = document.getElementById("form2");
const username = document.getElementById("username");
const email2 = document.getElementById("email2");
const password2 = document.getElementById("password2");
// LocalStorege
function criaUsuario(nome, email, senha) {
const user = {
nome: nome,
email: email,
senha: senha
};
localStorage.setItem("user", JSON.stringify(user));
}
// Checagem do usuário
form.addEventListener("submit", (event) => {
if (check_Input() == -1) {
event.preventDefault();
}
localStorage.setItem("username", JSON.stringify(username.value));
})
form2.addEventListener("submit", (event) => {
event.preventDefault();
check_Input2()
})
function check_Input() {
const emailValue = email.value.trim();
const passwordValue = password.value.trim();
let validador = 0;
if(emailValue === '') {
errorValidation(email);
validador = -1;
} else {
successValidation(email);
}
if(passwordValue === '') {
errorValidation(password);
validador = -1;
} else {
successValidation(password);
}
return validador;
}
function check_Input2() {
const usarnameValue = username.value.trim();
const email2Value = email2.value.trim();
const password2Value = password2.value.trim();
let validador = 0;
function validarCampo(valor, campo) {
if (valor === '') {
errorValidation(campo);
validador = -1;
} else {
successValidation(campo);
}
}
validarCampo(usarnameValue, username);
validarCampo(email2Value, email2);
validarCampo(password2Value, password2);
if (validador === 0) {
criaUsuario(usarnameValue, email2Value, password2Value);
}
}
function errorValidation(input) {
const formContent = input.parentElement;
formContent.className = 'form-content error'
}
function successValidation(input){
const formContent = input.parentElement;
formContent.className = 'form-content success'
}