Commit 0a1d0923 authored by Adrian's avatar Adrian
Browse files

cambios

parent 00272c6c
...@@ -6,18 +6,25 @@ ...@@ -6,18 +6,25 @@
<title>.:: Sitio ::.</title> <title>.:: Sitio ::.</title>
<link rel="stylesheet" href="./style.css"> <link rel="stylesheet" href="./style.css">
<script type="text/javascript"> <script type="text/javascript">
var url = 'http://localhost:5000/send'; var baseURL = 'http://localhost:5000';
function login () { function login () {
if (document.getElementById('user').value === 'admin' && document.getElementById('password').value === '123456') { service(baseURL + '/login', {
document.getElementById('login').style.display = 'none'; usuario: document.getElementById('user').value,
document.getElementById('data').style.display = 'block'; password: document.getElementById('password').value
} else { })
alert('Datos incorrectos'); .then((data) => {
} if (data.finalizado) {
window.localStorage.setItem('site_token', data.datos.token);
document.getElementById('login').style.display = 'none';
document.getElementById('data').style.display = 'block';
} else {
alert('Datos incorrectos');
}
});
} }
async function postData(url = '', data = {}) { async function service(url = '', data = {}, method = 'POST') {
const response = await fetch(url, { const response = await fetch(url, {
method: 'POST', method: method,
mode: 'cors', mode: 'cors',
cache: 'no-cache', cache: 'no-cache',
credentials: 'same-origin', credentials: 'same-origin',
...@@ -31,7 +38,7 @@ ...@@ -31,7 +38,7 @@
return await response.json(); return await response.json();
} }
function sendData () { function sendData () {
postData(url, { service(baseURL + '/send', {
titulo: document.querySelector('#title').value, titulo: document.querySelector('#title').value,
text: document.querySelector('#description').value text: document.querySelector('#description').value
}) })
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment