-
Notifications
You must be signed in to change notification settings - Fork 1
/
cliente.html
162 lines (153 loc) · 7.04 KB
/
cliente.html
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cadastro Cliente</title>
<link rel="stylesheet" href="./src/css/app.css">
<link rel="stylesheet" href="./src/css/inputAnimation.css">
<link rel="stylesheet" href="./src/css/buttonSalesforce.css">
<link rel="icon" href="./src/img/profile.png">
<script src="https://kit.fontawesome.com/141bc0b016.js" crossorigin="anonymous"></script>
<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<style>
html{
height: 120%;
}
.login-box{
min-width: 90%;
min-height: 90%;
}
</style>
</head>
<body>
<form method="post">
<div class="login-box">
<h2> Cadastro do Cliente</h2>
<div class="user-box">
<input type="text" id="name" autocomplete="off" onchange="validaLetras(document.getElementById('name'))" required=""/>
<label for="name">Nome:</label>
</div>
<div class="user-box">
<input type="text" id="mail" autocomplete="off" onchange="validaEmail(document.getElementById('mail'))" required=""/>
<label for="mail">E-mail:</label>
</div>
<div class="user-box">
<input type="password" id="senha" autocomplete="off" onchange="validaSenha(document.getElementById('senha'))" required=""/>
<label for="senha">Senha:</label>
</div>
<div class="user-box">
<input type="text" id="cpf" autocomplete="off" onchange="validarCPF(document.getElementById('cpf'))" required=""/>
<label for="cpf">CPF:</label>
</div>
<div class="user-box">
<input type="text" id="telefone" autocomplete="off" onchange="validaNulo(document.getElementById('telefone'))" required=""/>
<label for="tel">Telefone:</label>
</div>
<div class="user-box">
<input type="text" id="cep" autocomplete="off" onchange="validaNulo(document.getElementById('cep'))" required=""/>
<label for="cep">CEP:</label>
</div>
<div class="user-box">
<input type="text" id="cidade" autocomplete="off" onchange="validaLetras(document.getElementById('cidade'))" required=""/>
<label for="cdd">Cidade:</label>
</div>
<div class="user-box">
<input type="text" id="estado" autocomplete="off" onchange="validaLetras(document.getElementById('estado'))" required=""/>
<label for="est">Estado:</label>
</div>
<div class="divButton" id="btn" onClick="enviar()">
<i class="fa-regular fa-circle-check"></i>
CADASTRAR
</div>
</div>
</form>
<script type="module" src="https://www.gstatic.com/firebasejs/8.9.1/firebase-app.js"></script>
<script type="module" src="https://www.gstatic.com/firebasejs/8.9.1/firebase-database.js"></script>
<script type="module" src="https://www.gstatic.com/firebasejs/8.9.1/firebase-auth.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.11/jquery.mask.min.js"></script>
<script type="module" src="./src/scripts/firebaseConfig.js"></script>
<script type="text/javascript" src="./src/scripts/verificadores.js"></script>
<script type="text/javascript" src="./src/scripts/cadastrar.js"></script>
<script type="text/javascript">
$("#cpf").mask("000.000.000-00");
$("#telefone").mask("(00) 00000-0000");
$("#cep").mask("00000-000");
</script>
<script type="text/javascript">
async function enviar(){
var nome = document.getElementById('name');
var email = document.getElementById('mail');
var password = document.getElementById('senha');
var estado = document.getElementById('estado');
var telefone = document.getElementById('telefone');
var cpf = document.getElementById('cpf');
var cep = document.getElementById('cep');
var cidade = document.getElementById('cidade');
if(validaLetras(nome) &&
validaEmail(email) &&
validaNulo(password) &&
validarCPF(cpf) &&
validaNulo(cep) &&
validaNulo(telefone) &&
validaLetras(cidade) &&
validaLetras(estado)
){
var id = cpf.value.replaceAll('.', '');
id = id.replaceAll('-', '');
await cadastrarCliente(nome.value, email.value, password.value, estado.value, telefone.value, id, cep.value, cidade.value)
}
else{
Swal.fire({
icon: 'error',
title: 'Houve um erro!',
text: 'Verifique as informações e tente novamente',
})
}
}
async function cadastrarCliente(nome, email, password, estado, telefone, cpf, cep, cidade){
var cliente = firebase.database().ref('Cadastros/Clientes/' + cpf + '/');
var snapshot = await cliente.once('value')
if(snapshot.exists()){
Swal.fire({
icon: 'error',
title: 'Houve um erro!',
text: 'Esse cadastro já existe! Tente fazer o login!',
})
}
else{
firebase.database().ref('Cadastros/Clientes/' + cpf).set({
"Nome" : nome,
"Email" : email,
"Senha" : password,
"Estado" : estado,
"Telefone" : telefone,
"CPF" : cpf,
"CEP" : cep,
"Cidade" : cidade,
"obras" : '',
"class": 'c'
}).then(() => {
firebase.auth().createUserWithEmailAndPassword(email, password)
.then((userCredential) => {
var user = userCredential.user;
localStorage["auth"] = email
window.location.href = "main.html"
})
.catch((error) => {
var errorCode = error.code;
var errorMessage = error.message;
Swal.fire({
icon: 'error',
title: 'Houve um erro!',
text: 'Verifique as informações e tente novamente',
})
});
});
}
}
</script>
</body>
</html>