-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
141 lines (122 loc) · 7.04 KB
/
Copy pathindex.html
File metadata and controls
141 lines (122 loc) · 7.04 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
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
<!DOCTYPE html>
<html lang="es" class="bg-gray-50">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Documentor</title>
<script src="/assets/css/taiwling.js"></script>
<script src="/assets/js/vendor/chart.js""></script>
<meta name="description" content="" />
<meta name="author" content="Alexey Suzdalenko" />
<link rel="icon" type="image/png" href="/favicon.png">
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@100..900&display=swap" rel="stylesheet">
<meta name="theme-color" content="#4F46E5" /
</head>
<body>
<div class="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8 mt-10">
<div class="sm:mx-auto sm:w-full sm:max-w-sm">
<a href="/"><h2 class="mt-10 text-center text-2xl/9 font-bold tracking-tight text-gray-900">Documentor</h2></a>
</div>
<div class="mt-10 sm:mx-auto sm:w-full sm:max-w-sm">
<form class="space-y-6" action="#" method="POST">
<div id="divName">
<label for="email" class="block text-sm/6 font-medium text-gray-900">Nombre</label>
<div class="mt-2">
<input name="email" id="email" autocomplete="email" required class="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline-2 focus:-outline-offset-2 focus:outline-blue-600 sm:text-sm/6">
</div>
</div>
<div id="divEmail">
<div class="flex items-center justify-between">
<label for="password" class="block text-sm/6 font-medium text-gray-900">Contraseña</label>
</div>
<div class="mt-2">
<input type="password" name="password" id="password" autocomplete="current-password" required class="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline-2 focus:-outline-offset-2 focus:outline-blue-600 sm:text-sm/6">
</div>
</div>
<div style="display: none;" id="divEmailCode">
<div class="flex items-center justify-between">
<label for="password" class="block text-sm/6 font-medium text-gray-900">Introduzca el código que hemos enviado a su correo electrónico</label>
</div>
<div class="mt-2">
<input type="text" name="email_code" id="email_code" required class="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline-2 focus:-outline-offset-2 focus:outline-blue-600 sm:text-sm/6">
</div>
</div>
<div id="divSentEmailPassword">
<input onclick="loginApp()" type="button" class="flex w-full justify-center rounded-md bg-blue-700 px-3 py-1.5 text-sm/6 font-semibold text-white shadow-xs hover:bg-blue-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600 hover-a" value="Entrar">
</div>
<div id="divSentEmailCode" style="display: none;">
<input onclick="loginApp('need_have_email_code')" type="button" class="flex w-full justify-center rounded-md bg-blue-600 px-3 py-1.5 text-sm/6 font-semibold text-white shadow-xs hover:bg-blue-500 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600 hover-a" value="Enviar código">
</div>
</form>
</div>
</div>
<script src="/assets/js/0.config.js"></script>
<script src="/assets/js/4.notifications.js"></script>
<script>
function showInputEmailCode(){
document.getElementById('divName').style.display = 'none';
document.getElementById('divEmail').style.display = 'none';
document.getElementById('divSentEmailPassword').style.display = 'none';
document.getElementById('divEmailCode').style.display = 'block';
document.getElementById('divSentEmailCode').style.display = 'block';
}
function loginApp(x){
let username = document.getElementById('email').value.trim().toLowerCase();
let password = document.getElementById('password').value.trim();
let email_code = document.getElementById('email_code').value.trim().toLowerCase();
if(!username || !password){ return; }
if(!email_code && x == 'need_have_email_code'){ showM('Debe insertar el código que hemos enviado a su correo electrónico', 'warning'); return; }
let formData = new FormData();
formData.append('username', username);
formData.append('password', password);
formData.append('action', 'login');
formData.append('email_code', email_code);
document.getElementById('divSentEmailPassword').style.display = 'none';
fetch(HTTP_HOST+'mainapp/login/', {method:'POST', body: formData}).then(r => r.json()).then(r => { console.log(r); console.log(window.localStorage);
if(r && r.data && r.data.user_id > 0){
window.localStorage.setItem('user_id', r.data.user_id);
window.localStorage.setItem('username', username);
window.localStorage.setItem('password', password);
window.localStorage.setItem('role', r.data.role);
window.localStorage.setItem('permissions', r.data.permissions);
window.localStorage.setItem('action_pass', r.data.action_pass);
if(r.data.aviso == 'credenciales-correctos'){
showM('Credenciales correctos, enviando el código..');
showInputEmailCode();
}
if(r.data.aviso == 'codigo-incorrecto'){
// aqui instalo el Beaber en fetch js y paso a la pantalla de /dashboard
showM('Codigo insertado incorrecto', 'warning');
}
if(r.data.aviso == 'codigo-correcto'){
// aqui instalo el Beaber en fetch js y paso a la pantalla de /dashboard
showM('Codigo insertado correcto');
window.localStorage.setItem('token', r.data.token);
window.location.href = '/dashboard/#documentos-listado-general';
}
document.getElementById('email_code').value = '';
} else if (r.message){
showM(r.message, 'warning');
document.getElementById('divSentEmailPassword').style.display = 'block';
} else {
showM('Credenciales incorrectos', 'warning');
document.getElementById('divSentEmailPassword').style.display = 'block';
}
}).catch(e => {
showM('e34 '+e, 'error');
document.getElementById('divSentEmailPassword').style.display = 'block';
});
}
if(window.localStorage.getItem('username') && window.localStorage.getItem('password')){
document.getElementById('email').value = window.localStorage.getItem('username');
document.getElementById('password').value = window.localStorage.getItem('password');
}
console.log(window.localStorage.getItem('token'));
</script>
<style>
.hover-a{
cursor: pointer;
}
</style>
</body>
</html>