-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcadastro.js
26 lines (25 loc) · 1.14 KB
/
cadastro.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
$(document).ready(function (){
$("#cadastro").click(function (){
var user = $("#user").val();
var pass = $("#pass").val();
var repass = $("#repass").val();
if ( user == '' || pass == ''|| repass == ''){
$("#user").attr("class", "wrong_input w3-input w3-border");
$("#pass").attr("class", "wrong_input w3-input w3-border");
$("#repass").attr("class", "wrong_input w3-input w3-border");
$("#alert").html("Não deixe campos em branco.");
} else if(pass != repass){
$("#user").attr("class", "wrong_input w3-input w3-border");
$("#pass").attr("class", "wrong_input w3-input w3-border");
$("#repass").attr("class", "wrong_input w3-input w3-border");
$("#alert").html("As senhas devem ser iguais.");
} else {
var userobj = JSON.parse(localStorage.getItem("users"));
if(userobj == null) userobj = JSON.parse("{}");
if(user in userobj) $("#alert").html("Usuário já existe.");
else userobj[String(user)] = {password: pass, transactions: [], classes: {health: "health", bills: "bills", food: "food", fun: "fun"}};
localStorage.setItem("users", JSON.stringify(userobj));
document.location.href = "login.html";
}
});
});