login.js
1.49 KB
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
function LoginBoton(tc, validate, redirect) {
button = document.createElement("button");
button.value = "Enviar";
button.setAttribute("onclick", "if (validate('"+validate+"') == true) redirect('"+redirect+"')");
button.setAttribute("class","SendButton");
button.innerText = "Enviar";
tc.lastElementChild.children[0].appendChild(button);
}
function CreateErrorLogin(fc){
error = document.createElement("div");
error.id = "ErrorLogin";
error.innerText = "Usuario o Contraseña incorrectos";
error.className = "Error";
fc.appendChild(error);
}
function Redireccionar(bool, redirect){
if (bool == true) window.location.href = redirect;
else document.getElementById('ErrorLogin').style.display = "block";
}
function validate(url){
cookie = new CookieHandler;
data = Leer(document.getElementById('TabsContainer'))
if (data == false) return false;
let obj = {
"url" : "/validate",
"contentType" : "application/json",
"async" : false,
"data" : {
"url" : url,
"user" : data['Usuario'],
"password" : data['Contraseña'],
},
"success" : (response) => {
r = JSON.parse(response);
if (r.success == true) cookie.add("login", r.cookie, 8 * 60 * 60 * 1000); // 8 hours
}
}
ajax = new Ajax(obj);
ajax.post();
return true;
}
function redirect(url){
cookie = new CookieHandler;
window.location.href = url + "/" + cookie.get("login");
}