INCLUSION A CONSULTA XSYSTEM API.
This commit is contained in:
17
README.md
17
README.md
@@ -9,7 +9,8 @@ ejs
|
||||
mysql
|
||||
express-myconnection
|
||||
express
|
||||
morgan
|
||||
express-session: necesario para controlar las ssiones
|
||||
morgan: es un logger
|
||||
telegraf: agrega entradas y salidas, con muchas integraciones a una variedad de métricas, eventos y registros de contenedores y sistemas populares.
|
||||
nodemon
|
||||
express-fileupload
|
||||
@@ -29,6 +30,20 @@ npm install -s mysql express-myconnection express morgan telegraf nodemon ejs ex
|
||||
Para consumir la api de forma exterior que valida y/o consulta cedula o ruc.
|
||||
```bash
|
||||
npm i cors --save
|
||||
```
|
||||
|
||||
### para generar un id único
|
||||
```
|
||||
npm install --save uuid
|
||||
|
||||
const uuidv4 = require("uuid/v4");
|
||||
// Y ahora lo llamamos como función
|
||||
let idUnico = uuidv4();
|
||||
```
|
||||
### Modulo control de sessiones
|
||||
Para controlar las ssesiones
|
||||
```bash
|
||||
npm i express-session --save
|
||||
```
|
||||
|
||||
## Documentación
|
||||
|
||||
129
package-lock.json
generated
129
package-lock.json
generated
@@ -12,17 +12,19 @@
|
||||
"axios": "^0.26.0",
|
||||
"cors": "^2.8.5",
|
||||
"ejs": "^3.0.2",
|
||||
"express": "^4.17.1",
|
||||
"express": "^4.18.2",
|
||||
"express-fileupload": "^1.3.1",
|
||||
"express-myconnection": "^1.0.4",
|
||||
"express-session": "^1.17.3",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"morgan": "^1.10.0",
|
||||
"mysql": "^2.18.1",
|
||||
"nodejs-base64": "^2.0.0",
|
||||
"telegraf": "^3.37.0"
|
||||
"telegraf": "^3.37.0",
|
||||
"uuid": "^9.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.2"
|
||||
"nodemon": "^2.0.22"
|
||||
}
|
||||
},
|
||||
"node_modules/abbrev": {
|
||||
@@ -473,6 +475,51 @@
|
||||
"resolved": "https://registry.npmjs.org/express-myconnection/-/express-myconnection-1.0.4.tgz",
|
||||
"integrity": "sha1-h3YEn7+fJiIJz/21NbfHUJcz/1U="
|
||||
},
|
||||
"node_modules/express-session": {
|
||||
"version": "1.17.3",
|
||||
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.3.tgz",
|
||||
"integrity": "sha512-4+otWXlShYlG1Ma+2Jnn+xgKUZTMJ5QD3YvfilX3AcocOAbIkVylSWEklzALe/+Pu4qV6TYBj5GwOBFfdKqLBw==",
|
||||
"dependencies": {
|
||||
"cookie": "0.4.2",
|
||||
"cookie-signature": "1.0.6",
|
||||
"debug": "2.6.9",
|
||||
"depd": "~2.0.0",
|
||||
"on-headers": "~1.0.2",
|
||||
"parseurl": "~1.3.3",
|
||||
"safe-buffer": "5.2.1",
|
||||
"uid-safe": "~2.1.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/express-session/node_modules/cookie": {
|
||||
"version": "0.4.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
|
||||
"integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/express-session/node_modules/safe-buffer": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
]
|
||||
},
|
||||
"node_modules/express/node_modules/on-finished": {
|
||||
"version": "2.4.1",
|
||||
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
|
||||
@@ -1219,6 +1266,14 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/random-bytes": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz",
|
||||
"integrity": "sha512-iv7LhNVO047HzYR3InF6pUcUsPQiHTM1Qal51DcGSuZFBil1aBBWG5eHPNek7bvILMaYJ/8RU1e8w1AMdHmLQQ==",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/range-parser": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
|
||||
@@ -1515,6 +1570,17 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/uid-safe": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz",
|
||||
"integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==",
|
||||
"dependencies": {
|
||||
"random-bytes": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/undefsafe": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz",
|
||||
@@ -1542,6 +1608,18 @@
|
||||
"node": ">= 0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/uuid": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
|
||||
"integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
|
||||
"funding": [
|
||||
"https://github.com/sponsors/broofa",
|
||||
"https://github.com/sponsors/ctavan"
|
||||
],
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/vary": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
||||
@@ -1927,6 +2005,33 @@
|
||||
"resolved": "https://registry.npmjs.org/express-myconnection/-/express-myconnection-1.0.4.tgz",
|
||||
"integrity": "sha1-h3YEn7+fJiIJz/21NbfHUJcz/1U="
|
||||
},
|
||||
"express-session": {
|
||||
"version": "1.17.3",
|
||||
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.3.tgz",
|
||||
"integrity": "sha512-4+otWXlShYlG1Ma+2Jnn+xgKUZTMJ5QD3YvfilX3AcocOAbIkVylSWEklzALe/+Pu4qV6TYBj5GwOBFfdKqLBw==",
|
||||
"requires": {
|
||||
"cookie": "0.4.2",
|
||||
"cookie-signature": "1.0.6",
|
||||
"debug": "2.6.9",
|
||||
"depd": "~2.0.0",
|
||||
"on-headers": "~1.0.2",
|
||||
"parseurl": "~1.3.3",
|
||||
"safe-buffer": "5.2.1",
|
||||
"uid-safe": "~2.1.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"cookie": {
|
||||
"version": "0.4.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
|
||||
"integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA=="
|
||||
},
|
||||
"safe-buffer": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"filelist": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz",
|
||||
@@ -2455,6 +2560,11 @@
|
||||
"side-channel": "^1.0.4"
|
||||
}
|
||||
},
|
||||
"random-bytes": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz",
|
||||
"integrity": "sha512-iv7LhNVO047HzYR3InF6pUcUsPQiHTM1Qal51DcGSuZFBil1aBBWG5eHPNek7bvILMaYJ/8RU1e8w1AMdHmLQQ=="
|
||||
},
|
||||
"range-parser": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
|
||||
@@ -2694,6 +2804,14 @@
|
||||
"mime-types": "~2.1.24"
|
||||
}
|
||||
},
|
||||
"uid-safe": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz",
|
||||
"integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==",
|
||||
"requires": {
|
||||
"random-bytes": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"undefsafe": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz",
|
||||
@@ -2715,6 +2833,11 @@
|
||||
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
|
||||
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
|
||||
},
|
||||
"uuid": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
|
||||
"integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA=="
|
||||
},
|
||||
"vary": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
||||
|
||||
10
package.json
10
package.json
@@ -2,7 +2,7 @@
|
||||
"name": "app_sigma",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"main": "src/app.js",
|
||||
"scripts": {
|
||||
"dev": "nodemon src/app.js",
|
||||
"start": "node src/app.js"
|
||||
@@ -11,19 +11,21 @@
|
||||
"author": "Pablinux",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.2"
|
||||
"nodemon": "^2.0.22"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.26.0",
|
||||
"cors": "^2.8.5",
|
||||
"ejs": "^3.0.2",
|
||||
"express": "^4.17.1",
|
||||
"express": "^4.18.2",
|
||||
"express-fileupload": "^1.3.1",
|
||||
"express-myconnection": "^1.0.4",
|
||||
"express-session": "^1.17.3",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"morgan": "^1.10.0",
|
||||
"mysql": "^2.18.1",
|
||||
"nodejs-base64": "^2.0.0",
|
||||
"telegraf": "^3.37.0"
|
||||
"telegraf": "^3.37.0",
|
||||
"uuid": "^9.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
17
src/app.js
17
src/app.js
@@ -5,6 +5,8 @@ const mysql = require('mysql');
|
||||
const cloud_file = require('express-fileupload');
|
||||
const myConecction = require('express-myconnection');
|
||||
const cors_origins = require('cors');
|
||||
//inicio de sessiones
|
||||
const session = require('express-session');
|
||||
//const jwt = require('jwt');
|
||||
//const pool = require('./db.js');
|
||||
|
||||
@@ -18,6 +20,7 @@ const productosRutas = require('./rutas/rt_items');
|
||||
const generalesRutas = require('./rutas/rt_Generales');
|
||||
const cloud_rutas = require('./rutas/rt_cloud');
|
||||
const app_restaurant = require('./rutas/rt_apps');
|
||||
const app_arduino = require('./rutas/rt_arduino');
|
||||
|
||||
//configuraciones
|
||||
app.set('port',process.env.PORT||puerto);
|
||||
@@ -29,6 +32,13 @@ app.locals = global.config;
|
||||
|
||||
//***** CONTROL DE CORDS ******/
|
||||
app.use(cors_origins({origin:global.config.origin.any}));
|
||||
//*****inicio de sessiones*****//
|
||||
app.use(session({
|
||||
secret: global.config.sessionStorage.secretSession,//llave para cifrar
|
||||
resave: false,//no se guarde cada vez que se hace un cambio
|
||||
saveUninitialized: true,//guardar sesion aunque no haya datos
|
||||
cookie: { secure: false }//true solo se envia por https
|
||||
}));
|
||||
|
||||
//middlewares
|
||||
app.use(express.static(__dirname+'/public'));//para usar la carpeta public *js*css*img
|
||||
@@ -55,12 +65,15 @@ app.use('/', productosRutas);
|
||||
app.use('/', generalesRutas);
|
||||
app.use('/', cloud_rutas);
|
||||
app.use('/', app_restaurant);
|
||||
app.use('/', app_arduino);
|
||||
|
||||
//prueba de json directa
|
||||
app.get('/pruebaJson',function(req,res){
|
||||
req.session.acount = req.session.acount ? req.session.acount + 1 : 1;
|
||||
res.json([
|
||||
{nombre:"Tarea1",detalle:"programacion"},
|
||||
{nombre:"Tarea2",detalle:"Android Json"}
|
||||
{nombre:"Tarea2",detalle:"Android Json"},
|
||||
{ejecusion:req.session.acount,"id":req.sessionID},
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -69,5 +82,5 @@ app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
//inicia servidor
|
||||
app.listen(app.get('port'),() =>{
|
||||
console.log('Servidor Activo: App SIGMA Pedidos -> Puerto: '+puerto);
|
||||
console.log('Servidor Activo: App SIGMA Pedidos -> Puerto: '+puerto +' -> '+new Date().toLocaleString());
|
||||
});
|
||||
|
||||
@@ -20,6 +20,9 @@ const config = {
|
||||
empresa:"",
|
||||
role:"",
|
||||
},
|
||||
sessionStorage:{
|
||||
secretSession: "Microbot%",
|
||||
},
|
||||
origin:{
|
||||
whiteList : ['https://factura-e.net','https://app.factura-e.net'],
|
||||
any:{},
|
||||
@@ -28,7 +31,7 @@ const config = {
|
||||
key:"Microbot&"
|
||||
},
|
||||
server:{
|
||||
port:8086
|
||||
port:3001
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ controlador.verClientesJsonApp = (req, res) => {
|
||||
//next(err);
|
||||
}
|
||||
//console.log(rows);
|
||||
//var test = {"Items":[{"idt_prdcto":"1","codigo_prdcto":"CODIGOTEST","detalle_prdcto":"ITEM GENERADO","describe_prdcto":"DESCRIPCION DE ITEMS"}]};
|
||||
var client = { Clientes: rows };
|
||||
res.json(client);
|
||||
//res.render('clientesV',{ data:rows });
|
||||
@@ -157,20 +156,20 @@ controlador.app_pedidos_clientes = (req, res) => {
|
||||
|
||||
//CONSULTA CLIENTE CLOUD C.I-RUC => ruta:/busquedaSRI
|
||||
var data_url0 = 'http://www.ecuadorlegalonline.com/modulo/sri/consulta-ruc/ruc.api.php';
|
||||
var data_url1 = "https://xsystem.ddns.net/app/consulta_clientes.php";
|
||||
var data_url1 = "https://xsystem.ddns.net/app/clientes_cloud.php";
|
||||
var data_url2 = "http://sheyla2.dyndns.info/SRI/SRI.php";
|
||||
var data_url3 = "http://192.168.10.100:8000/test_post";
|
||||
var arrayUrl = [
|
||||
"http://www.ecuadorlegalonline.com/modulo/sri/consulta-ruc/ruc.api.php",
|
||||
"https://xsystem.ddns.net/app/consulta_clientes.php",
|
||||
"https://xsystem.ddns.net/api/clientes_cloud.php",
|
||||
"http://sheyla2.dyndns.info/SRI/SRI.php",
|
||||
"http://192.168.10.100:8000/test_post",
|
||||
"solo testing"
|
||||
];
|
||||
controlador.buscarCli_sri = (req, res) => {
|
||||
var idCli = req.query.ruc;
|
||||
var idCli = req.query.ID_CLIENTE;
|
||||
console.log(`Peticion => Consulta RUC: ${idCli}`);
|
||||
let selc = 2;
|
||||
let selc = 1;
|
||||
|
||||
switch (selc) {
|
||||
case 0:
|
||||
@@ -184,11 +183,13 @@ controlador.buscarCli_sri = (req, res) => {
|
||||
});
|
||||
break;
|
||||
case 1:
|
||||
axios.post(arrayUrl[selc] + "?ruc=" + idCli)
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: arrayUrl[selc]+"?ID_CLIENTE="+idCli,
|
||||
})
|
||||
.then(function (resp_sri) {
|
||||
console.log(resp_sri.data);
|
||||
var consulta = { "resp_consulta": resp_sri };
|
||||
res.json(consulta);
|
||||
res.json(resp_sri.data);
|
||||
});
|
||||
break;
|
||||
case 2:
|
||||
@@ -228,16 +229,44 @@ controlador.api_consultaCliente = (req, res) => {
|
||||
//console.log(req.query.id);
|
||||
console.log(`Peticion => Consulta ID: ${idCli}`);
|
||||
req.getConnection((err, conn) => {
|
||||
conn.query('SELECT client_nombre as nombre,client_razonSocial as nombre_comercial,client_direccion as direccion,IFNULL(client_celular,client_telefono) as telefono,client_email as email FROM clientes WHERE client_rucCed = ?', [idCli], (err, rows) => {
|
||||
conn.query('SELECT client_nombre as nombre,client_razonSocial as nombre_comercial,client_Ciudad as ciudad,client_direccion as direccion,IFNULL(client_celular,client_telefono) as telefono,client_email as email FROM clientes WHERE client_rucCed = ?', [idCli], (err, rows) => {
|
||||
//conn.query('SELECT * FROM clientes WHERE client_rucCed = ?',[idCli],(err,rows)=>{
|
||||
if (rows.length > 0) {
|
||||
console.log("Encontrado en Servidor Local:");
|
||||
res.json(rows);
|
||||
} else {
|
||||
axios.post(arrayUrl[2] + "?ruc=" + idCli)
|
||||
axios.post(arrayUrl[1] + "?ID_CLIENTE=" + idCli)
|
||||
.then(function (resp_sri) {
|
||||
console.log("Encontrado en Servidor SRI:");
|
||||
//console.log(resp_sri.data);
|
||||
console.log(resp_sri.data);
|
||||
var resp = resp_sri.data;
|
||||
if(resp.length > 0){
|
||||
var obj_json = {
|
||||
nombre: resp[0].CLI_NOMBRE,
|
||||
nombre_comercial: resp[0].CLI_NOMBRE,
|
||||
direccion: resp[0].CLI_DIRECCION,
|
||||
ciudad:"", telefono:
|
||||
resp[0].CLI_TELEFONOS,
|
||||
email: resp[0].CLI_EMAIL };
|
||||
res.json(obj_json);
|
||||
}else{
|
||||
res.json({"RESP":"DATA NO ENCONTRADA"});
|
||||
//axios.post(arrayUrl[1] + "?ID_CLIENTE=" + idCli).then(function (resp_sri) {});
|
||||
}
|
||||
}).catch(function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function consulta_clientes(idCli) {
|
||||
if(false){
|
||||
axios.post(arrayUrl[1] + "?ID_CLIENTE=" + idCli)
|
||||
.then(function (resp_sri) {
|
||||
console.log("Encontrado en Servidor SRI:");
|
||||
console.log(resp_sri.data);
|
||||
var data_toArray = resp_sri.data;
|
||||
let arr = data_toArray.split('***');
|
||||
//console.log(arr);
|
||||
@@ -247,14 +276,7 @@ controlador.api_consultaCliente = (req, res) => {
|
||||
}).catch(function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function consulta_clientes(idCli) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ const axios = require('axios').default;
|
||||
const jwt = require('jsonwebtoken');
|
||||
const config = require('../config');
|
||||
const { base64encode, base64decode } = require('nodejs-base64');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
controlador.verVentasJson = (req, res) => {
|
||||
req.getConnection((err, conn) => {
|
||||
@@ -60,12 +61,23 @@ function stringTo_md5(data_string) {
|
||||
console.log("MD5: ", md5);
|
||||
return md5;
|
||||
}
|
||||
async function keygen(conection) {
|
||||
var key = "";
|
||||
await conection.query(`SELECT * FROM empresa_datos`, (err, rows) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
key = base64encode(rows[0].RUC);
|
||||
}
|
||||
});
|
||||
return key;
|
||||
}
|
||||
//************* FORM LOGIN DEMO ****************//
|
||||
controlador.login_test = (req, res) => {
|
||||
res.render('login_test');
|
||||
};
|
||||
|
||||
|
||||
var sesion_login = {"UID":"","SESSION":"","KEY":""};
|
||||
//************* GENERA TOKENS ****************//
|
||||
controlador.auth_keygen = async (req, res) => {
|
||||
var datUsr = base64decode(req.body.data);
|
||||
@@ -88,6 +100,8 @@ controlador.auth_keygen = async (req, res) => {
|
||||
var ape = rows[0].apellido;
|
||||
const token = jwt.sign(jsonDat, config.secret.key);
|
||||
var auth = { auth: [{ "apellido": ape, "nombre": nom, "key": key, token: token }] };
|
||||
sesion_login.SESSION = req.sessionID;
|
||||
sesion_login.KEY = key;
|
||||
//console.log(auth);
|
||||
res.json(auth);
|
||||
} else {
|
||||
@@ -104,12 +118,19 @@ controlador.auth_keygen = async (req, res) => {
|
||||
controlador.auth_token = async (req, res) => {
|
||||
console.log(req.body.data);
|
||||
var token = req.body.data;
|
||||
let idUnico = uuidv4();
|
||||
if (!token) {
|
||||
return res.status(401).json({ auth: false, message: 'No token provided' });
|
||||
}
|
||||
try{
|
||||
await req.getConnection(async (error, conn, next) => {
|
||||
//var key = await keygen(conn);
|
||||
var decoded = jwt.verify(token, config.secret.key);
|
||||
res.json(decoded);
|
||||
console.log(decoded);
|
||||
sesion_login.UID = idUnico;
|
||||
res.json(sesion_login);
|
||||
});
|
||||
|
||||
}catch(err){
|
||||
res.json({ auth: false, message: 'Unauthorized: '+err.message });
|
||||
}
|
||||
|
||||
17
src/controladores/controlador_arduino.js
Normal file
17
src/controladores/controlador_arduino.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const controlador = {};
|
||||
/*const axios = require('axios').default;
|
||||
const jwt = require('jsonwebtoken');
|
||||
const config = require('../config');
|
||||
const { base64encode, base64decode } = require('nodejs-base64');
|
||||
const { v4: uuidv4 } = require('uuid');*/
|
||||
|
||||
|
||||
//********* PRUEBA Y RECECION DE DATOS ********//
|
||||
controlador.recibe_datos = (req, res) => {
|
||||
console.log(req.body);
|
||||
res.send({PRT_NUM:3,PRT_EST:1,msg:"MENSAJE AL DISPLAY ",status:200});
|
||||
//res.render('panel_control');
|
||||
};
|
||||
|
||||
|
||||
module.exports = controlador;
|
||||
8
src/rutas/rt_arduino.js
Normal file
8
src/rutas/rt_arduino.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const express = require('express');
|
||||
const rutas = express.Router();
|
||||
|
||||
const controlador_init = require('../controladores/controlador_arduino');
|
||||
|
||||
rutas.post('/test_recibe_json/', controlador_init.recibe_datos);//testing json reccepcion server
|
||||
|
||||
module.exports = rutas;
|
||||
Reference in New Issue
Block a user