Actualizacion del proyecto mejoras y cambios en autorizacion , ahora es por jwt

parent 0ff928fa
const Joi = require('joi');
class szerCampania{
constructor(uid){
this.uid = uid;
}
}
function validate(json){
const schema =Joi.object({
'uid' : Joi.string().required().messages({
'string.base': `"uid" debe ser una cadena de caracteres`,
'string.empty': `"uid" no puede estar vacío`,
'any.required': `"uid" es un campo requerido`
}),
});
return schema.validate(json);
}
module.exports = szerCampania;
module.exports.validate = validate;
\ No newline at end of file
const Joi = require("joi");
class szerUsuario {
constructor(user, password, name) {
this.name = name;
this.user = user;
this.password = password;
}
}
function validate(json) {
const schema = Joi.object({
name: Joi.string().min(10).max(50).required().messages({
"string.base": `"name" debe ser una cadena de caracteres`,
"string.empty": `"name" no puede estar vacío`,
"any.required": `"name" es un campo requerido`,
"string.min": `"name" no posee el tamaño correcto`,
"string.max": `"name" no posee el tamaño correcto`,
}),
user: Joi.string().min(6).max(6).required().messages({
"string.base": `"user" debe ser una cadena de caracteres`,
"string.empty": `"user" no puede estar vacío`,
"any.required": `"user" es un campo requerido`,
"string.min": `"user" no posee el tamaño correcto`,
"string.max": `"user" no posee el tamaño correcto`,
}),
password: Joi.string().min(8).max(255).required().messages({
"string.base": `"password" debe ser una cadena de caracteres`,
"string.empty": `"password" no puede estar vacío`,
"any.required": `"password" es un campo requerido`,
"string.min": `"password" no posee el tamaño correcto`,
"string.max": `"password" no posee el tamaño correcto`,
}),
});
return schema.validate(json);
}
module.exports = szerUsuario;
module.exports.validate = validate;
......@@ -4,7 +4,8 @@
"OK": 200,
"BAD_REQUEST": 400,
"NOT_FOUND": 404,
"ERROR": 500
"ERROR": 500,
"UNAUTHORIZED":401
},
"HTML_SECTIONS": {
"HEAD": 1,
......
......@@ -11,8 +11,10 @@
"DBUSER": "mcafee_admin_territorios",
"DBPSSW": "HSuwshhuw43&%1253"
},
"basicAuth": {
"customAuth": {
"NAME" : "G3ARLABS",
"USER": "userApi",
"PASS" : "34lq4od8usda"
}
"PASS" : "$2b$10$nd1vR4YSZS/o5ScJyVZZIOiFglpuVOLrCOfY35.YAidlwvWERe3G2"
},
"pkj": "G3arl@abs"
}
\ No newline at end of file
......@@ -11,9 +11,11 @@
"DBUSER": "mcafee_admin_territorios",
"DBPSSW": "HSuwshhuw43&%1253"
},
"basicAuth": {
"customAuth": {
"NAME" : "G3ARLABS",
"USER": "userApi",
"PASS" : "34lq4od8usda"
}
"PASS" : "$2b$10$nd1vR4YSZS/o5ScJyVZZIOiFglpuVOLrCOfY35.YAidlwvWERe3G2"
},
"pkj": "G3arl@abs"
}
\ No newline at end of file
const config = require('config');
const serverApp = require('./middleware/app');
const log = require('./middleware/logger');
const serverApp = require('./middleware/server-init');
const log = require('./utils/logger');
/*Trick para problema con eventListeners maximos*/
require('events').EventEmitter.prototype._maxListeners = 100;
/**
* Se activa la conexion a la base de datos en modalidad pool
**/
console.log(`Aplicacion : ${config.get("name")} `);
log.logger.info(`Aplicacion : ${config.get("name")} `);
/*
* Solo en ambientes de desarrollo locales se coloca el puerto directamente al iniciar la aplicacion
* en servidores, se debe obtener del objeto global "process"
*/
const port = process.env.PORT || config.get("server.PORT");
serverApp.listenPort(port);
//crear login para obtener jwt valido para poder realizar las peticiones hacia el endpoint
\ No newline at end of file
app.js:
const basicAuth = require("express-basic-auth");
const config = require("config");
server.use((req, res, next) => {
console.log("Verificando Credenciales...");
next();
});
/**
* MiddleWare Function : Autorizacion basica permitida para la api generada
*/
server.use(
basicAuth({
authorizer: myAuthorizer,
unauthorizedResponse: getUnauthorizedResponse,
})
);
server.use((req, res, next) => {
console.log("Autentificado correctamente!...");
next();
});
function myAuthorizer(username, password) {
const userMatches = basicAuth.safeCompare(
username,
config.get("basicAuth.USER")
);
const passwordMatches = basicAuth.safeCompare(
password,
config.get("basicAuth.PASS")
);
return userMatches & passwordMatches;
}
function getUnauthorizedResponse(req) {
return req.auth
? `Las credenciales ${req.auth.user}:${req.auth.password} no son válidas.`
: "No se ingresaron credenciales";
}
module.exports = function (handler){
return async (req,res,next) => {
try{
handler(req,res);
}catch(ex){
next(ex);
}
}
}
const jwt = require('jsonwebtoken');
const config = require('config');
const log = require('../utils/logger');
module.exports=function(req,res,next){
if(!req.header('x-auth-mcafee-token')){
let error = new Error('Acceso denegado.No existe un token válido.');
log.logger.error(error);
return res.status(config.get('constants.HTTP_STATUS_CODE.UNAUTHORIZED')).json({code : config.get('constants.HTTP_STATUS_CODE.UNAUTHORIZED') ,error : error})
}
try{
const decoded = jwt.decode(req.header('x-auth-mcafee-token'),config.get('pkj'));
if(!decoded) {
let error = new Error('Token con formato incorrecto.');
log.logger.error(error);
return res.status(config.get('constants.HTTP_STATUS_CODE.UNAUTHORIZED')).json({code : config.get('constants.HTTP_STATUS_CODE.UNAUTHORIZED') ,error : error})
}
next();
}catch(ex){
let error = new Error('Token Inválido');
log.logger.error(error);
res.status(config.get('constants.HTTP_STATUS_CODE.BAD_REQUEST')).json({code:config.get('constants.HTTP_STATUS_CODE.BAD_REQUEST') ,error : error});
}
}
\ No newline at end of file
const config = require ('config');
const bcrypt = require("bcrypt");
module.exports = function (req, res, next) {
//Validacion de nombre empresa unico
if (req.body.name !== config.get("customAuth.NAME")){
log.logger.error(`Nombre ${req.body.user} invalido...`);
return res
.status(config.get("constants.HTTP_STATUS_CODE.BAD_REQUEST"))
.json(new Error("Identificacion no válida"));
}
//Validacion de nombre de usuario
if (req.body.user !== config.get("customAuth.USER")){
log.logger.error(`Usuario ${req.body.user} invalido...`);
return res
.status(config.get("constants.HTTP_STATUS_CODE.BAD_REQUEST"))
.json(new Error("Usuario y/o Password inválido"));
}
//Validacion de password
if (!bcrypt.compare(req.body.password, config.get('customAuth.PASS'))){
log.logger.error(`Password ${req.body.password} invalido...`);
return res
.status(config.get("constants.HTTP_STATUS_CODE.BAD_REQUEST"))
.json(new Error("Usuario y/o Password inválido"));
}
next();
}
\ No newline at end of file
const config = require("config");
const log = require('../utils/logger');
const winston = require('winston');
module.exports = (error, req, res, next) => {
log.logger.error(error);
res
.status(config.get("constants.HTTP_STATUS_CODE.ERROR"))
.json({
code: config.get("constants.HTTP_STATUS_CODE.ERROR"),
error: new Error(error).message,
});
};
/**
* Configurations of logger.
*/
const appRoot = require('app-root-path');
const winston = require("winston");
var options = {
error: { /*Se almacena registro en archivo de error*/
level: 'error',
name: 'error-file',
filename: `${appRoot}/logs/error.log`,
handleExceptions: true,
json: true,
maxsize: 5242880, // 5MB
maxFiles: 100,
colorize: true,
datePattern: "yyyy-MM-dd-",
prepend: true,
},
info: {/*Se almacena registro en archivo de aplicacion*/
level: 'info',
name: 'success-file',
filename: `${appRoot}/logs/app.log`,
handleExceptions: true,
json: true,
maxsize: 5242880, // 5MB
maxFiles: 100,
colorize: true,
datePattern: "yyyy-MM-dd-",
prepend: true,
},
console: {/*Log que va directo a la consola*/
level: 'debug',
handleExceptions: true,
json: false,
colorize: true,
},
};
const consoleConfig = [
new winston.transports.Console(options.console),
new winston.transports.File(options.error),
new winston.transports.File(options.info),
];
const createLogger = winston.createLogger({
transports: consoleConfig,
exitOnError: false, // do not exit on handled exceptions
});
module.exports.logger = createLogger;
const config = require("config");
require('express-async-errors');
const error = require('../middleware/error');
const express = require("express");
const basicAuth = require("express-basic-auth");
const userAgentValidator = require("express-useragent");
const server = express();
const campanias = require('../routes/campanias');
const auth = require('../routes/auth');
const internal = require('../routes/internal');
server.use((req, res, next) => {
console.log("Verificando Credenciales...");
next();
});
/**
* MiddleWare Function : Autorizacion basica permitida para la api generada
*/
server.use(
basicAuth({
authorizer: myAuthorizer,
unauthorizedResponse: getUnauthorizedResponse,
})
);
server.use((req, res, next) => {
console.log("Autentificado correctamente!...");
next();
});
function myAuthorizer(username, password) {
const userMatches = basicAuth.safeCompare(
username,
config.get("basicAuth.USER")
);
const passwordMatches = basicAuth.safeCompare(
password,
config.get("basicAuth.PASS")
);
return userMatches & passwordMatches;
}
function getUnauthorizedResponse(req) {
return req.auth
? `Las credenciales ${req.auth.user}:${req.auth.password} no son válidas.`
: "No se ingresaron credenciales";
}
/**
* MiddleWare Function: Verifica que el req.body sea json y lo trata como tal
......@@ -73,8 +37,9 @@ server.use(userAgentValidator.express());
* MiddleWare Function : Se activa la utilizacion de rutas para campanias
*/
server.use('/endpoint/campania', campanias);
server.use('/endpoint/auth', auth);
server.use('/endpoint/internal', internal)
server.use(error);
/**
* Definicion de funciones asociadas a endpoints
......
const Joi = require('joi');
class szerCampaniaValidator{
validate(szerCampania){
const schema =Joi.object({
'uid' : Joi.string().required().messages({
'string.base': `"uid" debe ser una cadena de caracteres`,
'string.empty': `"uid" no puede estar vacío`,
'any.required': `"uid" es un campo requerido`
}),
});
return schema.validate(szerCampania, this);
}
}
module.exports = szerCampaniaValidator;
\ No newline at end of file
......@@ -45,6 +45,11 @@
"@hapi/hoek": "^9.0.0"
}
},
"abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
},
"accepts": {
"version": "1.3.7",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
......@@ -64,6 +69,20 @@
"resolved": "https://registry.npmjs.org/app-root-path/-/app-root-path-3.0.0.tgz",
"integrity": "sha512-qMcx+Gy2UZynHjOHOIXPNvpf+9cjvk3cWrBBK7zg4gH9+clobJRb9NGzcT7mQTcV/6Gm/1WelUtqxVXnNlrwcw=="
},
"aproba": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
"integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw=="
},
"are-we-there-yet": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz",
"integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==",
"requires": {
"delegates": "^1.0.0",
"readable-stream": "^2.0.6"
}
},
"array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
......@@ -74,6 +93,11 @@
"resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz",
"integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw=="
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
"basic-auth": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz",
......@@ -82,6 +106,15 @@
"safe-buffer": "5.1.2"
}
},
"bcrypt": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/bcrypt/-/bcrypt-5.0.0.tgz",
"integrity": "sha512-jB0yCBl4W/kVHM2whjfyqnxTmOHkCX4kHEa5nYKSoGeYe8YrjTYTc87/6bwt1g8cmV0QrbhKriETg9jWtcREhg==",
"requires": {
"node-addon-api": "^3.0.0",
"node-pre-gyp": "0.15.0"
}
},
"bignumber.js": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz",
......@@ -113,11 +146,30 @@
"type-is": "~1.6.17"
}
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"buffer-equal-constant-time": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
"integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk="
},
"bytes": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
"integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg=="
},
"chownr": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz",
"integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg=="
},
"cli-color": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/cli-color/-/cli-color-1.4.0.tgz",
......@@ -152,6 +204,11 @@
}
}
},
"code-point-at": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
"integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c="
},
"color": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/color/-/color-3.0.0.tgz",
......@@ -197,6 +254,11 @@
"text-hex": "1.0.x"
}
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"config": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/config/-/config-3.3.2.tgz",
......@@ -205,6 +267,11 @@
"json5": "^2.1.1"
}
},
"console-control-strings": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
"integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4="
},
"content-disposition": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz",
......@@ -250,6 +317,16 @@
"ms": "2.0.0"
}
},
"deep-extend": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
"integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA=="
},
"delegates": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz",
"integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o="
},
"denque": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz",
......@@ -265,6 +342,11 @@
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
},
"detect-libc": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz",
"integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups="
},
"duration": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/duration/-/duration-0.2.2.tgz",
......@@ -274,6 +356,14 @@
"es5-ext": "~0.10.46"
}
},
"ecdsa-sig-formatter": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
"integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==",
"requires": {
"safe-buffer": "^5.0.1"
}
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
......@@ -385,6 +475,11 @@
"vary": "~1.1.2"
}
},
"express-async-errors": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/express-async-errors/-/express-async-errors-3.1.1.tgz",
"integrity": "sha512-h6aK1da4tpqWSbyCa3FxB/V6Ehd4EEB15zyQq9qe75OZBp0krinNKuH4rAY+S/U/2I36vdLAUFSjQJ+TFmODng=="
},
"express-basic-auth": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/express-basic-auth/-/express-basic-auth-1.2.0.tgz",
......@@ -460,6 +555,47 @@
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
},
"fs-minipass": {
"version": "1.2.7",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.7.tgz",
"integrity": "sha512-GWSSJGFy4e9GUeCcbIkED+bgAoFyj7XF1mV8rma3QW4NIqX9Kyx79N/PF61H5udOV3aY1IaMLs6pGbH71nlCTA==",
"requires": {
"minipass": "^2.6.0"
}
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
},
"gauge": {
"version": "2.7.4",
"resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz",
"integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=",
"requires": {
"aproba": "^1.0.3",
"console-control-strings": "^1.0.0",
"has-unicode": "^2.0.0",
"object-assign": "^4.1.0",
"signal-exit": "^3.0.0",
"string-width": "^1.0.1",
"strip-ansi": "^3.0.1",
"wide-align": "^1.1.0"
}
},
"glob": {
"version": "7.1.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"has-ansi": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-3.0.0.tgz",
......@@ -480,6 +616,11 @@
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
},
"has-unicode": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz",
"integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk="
},
"http-errors": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
......@@ -500,11 +641,33 @@
"safer-buffer": ">= 2.1.2 < 3"
}
},
"ignore-walk": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-3.0.3.tgz",
"integrity": "sha512-m7o6xuOaT1aqheYHKf8W6J5pYH85ZI9w077erOzLje3JsB1gkafkAhHHY19dqjulgIZHFm32Cp5uNZgcQqdJKw==",
"requires": {
"minimatch": "^3.0.4"
}
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"requires": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"ini": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz",
"integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw=="
},
"ipaddr.js": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
......@@ -515,6 +678,14 @@
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz",
"integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ=="
},
"is-fullwidth-code-point": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
"requires": {
"number-is-nan": "^1.0.0"
}
},
"is-promise": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz",
......@@ -550,6 +721,49 @@
"minimist": "^1.2.5"
}
},
"jsonwebtoken": {
"version": "8.5.1",
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz",
"integrity": "sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==",
"requires": {
"jws": "^3.2.2",
"lodash.includes": "^4.3.0",
"lodash.isboolean": "^3.0.3",
"lodash.isinteger": "^4.0.4",
"lodash.isnumber": "^3.0.3",
"lodash.isplainobject": "^4.0.6",
"lodash.isstring": "^4.0.1",
"lodash.once": "^4.0.0",
"ms": "^2.1.1",
"semver": "^5.6.0"
},
"dependencies": {
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
}
}
},
"jwa": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz",
"integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==",
"requires": {
"buffer-equal-constant-time": "1.0.1",
"ecdsa-sig-formatter": "1.0.11",
"safe-buffer": "^5.0.1"
}
},
"jws": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz",
"integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==",
"requires": {
"jwa": "^1.4.1",
"safe-buffer": "^5.0.1"
}
},
"kareem": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/kareem/-/kareem-2.3.1.tgz",
......@@ -560,6 +774,41 @@
"resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz",
"integrity": "sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A=="
},
"lodash.includes": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
"integrity": "sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8="
},
"lodash.isboolean": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz",
"integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY="
},
"lodash.isinteger": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz",
"integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M="
},
"lodash.isnumber": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz",
"integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w="
},
"lodash.isplainobject": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
"integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs="
},
"lodash.isstring": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz",
"integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE="
},
"lodash.once": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
"integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w="
},
"log": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/log/-/log-6.0.0.tgz",
......@@ -668,11 +917,44 @@
"mime-db": "1.44.0"
}
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"minipass": {
"version": "2.9.0",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-2.9.0.tgz",
"integrity": "sha512-wxfUjg9WebH+CUDX/CdbRlh5SmfZiy/hpkxaRI16Y9W56Pa75sWgd/rvFilSgrauD9NyFymP/+JFV3KwzIsJeg==",
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
}
},
"minizlib": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.3.3.tgz",
"integrity": "sha512-6ZYMOEnmVsdCeTJVE0W9ZD+pVnE8h9Hma/iOwwRDsdQoePpoX56/8B6z3P9VNwppJuBKNRuFDRNRqRWexT9G9Q==",
"requires": {
"minipass": "^2.9.0"
}
},
"mkdirp": {
"version": "0.5.5",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
"requires": {
"minimist": "^1.2.5"
}
},
"moment": {
"version": "2.29.1",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
......@@ -779,6 +1061,31 @@
"sqlstring": "2.3.1"
}
},
"needle": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/needle/-/needle-2.5.2.tgz",
"integrity": "sha512-LbRIwS9BfkPvNwNHlsA41Q29kL2L/6VaOJ0qisM5lLWsTV3nP15abO5ITL6L81zqFhzjRKDAYjpcBcwM0AVvLQ==",
"requires": {
"debug": "^3.2.6",
"iconv-lite": "^0.4.4",
"sax": "^1.2.4"
},
"dependencies": {
"debug": {
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
"requires": {
"ms": "^2.1.1"
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
}
}
},
"negotiator": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
......@@ -789,6 +1096,81 @@
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz",
"integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw="
},
"node-addon-api": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.0.2.tgz",
"integrity": "sha512-+D4s2HCnxPd5PjjI0STKwncjXTUKKqm74MDMz9OPXavjsGmjkvwgLtA5yoxJUdmpj52+2u+RrXgPipahKczMKg=="
},
"node-pre-gyp": {
"version": "0.15.0",
"resolved": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.15.0.tgz",
"integrity": "sha512-7QcZa8/fpaU/BKenjcaeFF9hLz2+7S9AqyXFhlH/rilsQ/hPZKK32RtR5EQHJElgu+q5RfbJ34KriI79UWaorA==",
"requires": {
"detect-libc": "^1.0.2",
"mkdirp": "^0.5.3",
"needle": "^2.5.0",
"nopt": "^4.0.1",
"npm-packlist": "^1.1.6",
"npmlog": "^4.0.2",
"rc": "^1.2.7",
"rimraf": "^2.6.1",
"semver": "^5.3.0",
"tar": "^4.4.2"
}
},
"nopt": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.3.tgz",
"integrity": "sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==",
"requires": {
"abbrev": "1",
"osenv": "^0.1.4"
}
},
"npm-bundled": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/npm-bundled/-/npm-bundled-1.1.1.tgz",
"integrity": "sha512-gqkfgGePhTpAEgUsGEgcq1rqPXA+tv/aVBlgEzfXwA1yiUJF7xtEt3CtVwOjNYQOVknDk0F20w58Fnm3EtG0fA==",
"requires": {
"npm-normalize-package-bin": "^1.0.1"
}
},
"npm-normalize-package-bin": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-1.0.1.tgz",
"integrity": "sha512-EPfafl6JL5/rU+ot6P3gRSCpPDW5VmIzX959Ob1+ySFUuuYHWHekXpwdUZcKP5C+DS4GEtdJluwBjnsNDl+fSA=="
},
"npm-packlist": {
"version": "1.4.8",
"resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.8.tgz",
"integrity": "sha512-5+AZgwru5IevF5ZdnFglB5wNlHG1AOOuw28WhUq8/8emhBmLv6jX5by4WJCh7lW0uSYZYS6DXqIsyZVIXRZU9A==",
"requires": {
"ignore-walk": "^3.0.1",
"npm-bundled": "^1.0.1",
"npm-normalize-package-bin": "^1.0.1"
}
},
"npmlog": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz",
"integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==",
"requires": {
"are-we-there-yet": "~1.1.2",
"console-control-strings": "~1.1.0",
"gauge": "~2.7.3",
"set-blocking": "~2.0.0"
}
},
"number-is-nan": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz",
"integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0="
},
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
},
"object-hash": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-2.0.3.tgz",
......@@ -802,6 +1184,14 @@
"ee-first": "1.1.1"
}
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"requires": {
"wrappy": "1"
}
},
"one-time": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/one-time/-/one-time-1.0.0.tgz",
......@@ -810,11 +1200,35 @@
"fn.name": "1.x.x"
}
},
"os-homedir": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz",
"integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M="
},
"os-tmpdir": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ="
},
"osenv": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz",
"integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==",
"requires": {
"os-homedir": "^1.0.0",
"os-tmpdir": "^1.0.0"
}
},
"parseurl": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
},
"path-to-regexp": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
......@@ -855,6 +1269,17 @@
"unpipe": "1.0.0"
}
},
"rc": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz",
"integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==",
"requires": {
"deep-extend": "^0.6.0",
"ini": "~1.3.0",
"minimist": "^1.2.0",
"strip-json-comments": "~2.0.1"
}
},
"readable-stream": {
"version": "2.3.7",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz",
......@@ -888,6 +1313,14 @@
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz",
"integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
},
"rimraf": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz",
"integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==",
"requires": {
"glob": "^7.1.3"
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
......@@ -907,6 +1340,11 @@
"sparse-bitfield": "^3.0.3"
}
},
"sax": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
},
"semver": {
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
......@@ -950,6 +1388,11 @@
"send": "0.17.1"
}
},
"set-blocking": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc="
},
"setprototypeof": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
......@@ -960,6 +1403,11 @@
"resolved": "https://registry.npmjs.org/sift/-/sift-7.0.1.tgz",
"integrity": "sha512-oqD7PMJ+uO6jV9EQCl0LrRw1OwsiPsiFQR5AR30heR+4Dl7jBBbDLnNvWiak20tzZlSE1H7RB30SX/1j/YYT7g=="
},
"signal-exit": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz",
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA=="
},
"simple-swizzle": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz",
......@@ -1005,6 +1453,16 @@
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
},
"string-width": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
"strip-ansi": "^3.0.0"
}
},
"string_decoder": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
......@@ -1013,6 +1471,19 @@
"safe-buffer": "~5.1.0"
}
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"requires": {
"ansi-regex": "^2.0.0"
}
},
"strip-json-comments": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz",
"integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo="
},
"supports-color": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz",
......@@ -1021,6 +1492,20 @@
"has-flag": "^3.0.0"
}
},
"tar": {
"version": "4.4.13",
"resolved": "https://registry.npmjs.org/tar/-/tar-4.4.13.tgz",
"integrity": "sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA==",
"requires": {
"chownr": "^1.1.1",
"fs-minipass": "^1.2.5",
"minipass": "^2.8.6",
"minizlib": "^1.2.1",
"mkdirp": "^0.5.0",
"safe-buffer": "^5.1.2",
"yallist": "^3.0.3"
}
},
"text-hex": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/text-hex/-/text-hex-1.0.0.tgz",
......@@ -1084,6 +1569,14 @@
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
},
"wide-align": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz",
"integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==",
"requires": {
"string-width": "^1.0.2 || 2"
}
},
"winston": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/winston/-/winston-3.3.3.tgz",
......@@ -1131,6 +1624,16 @@
"readable-stream": "^2.3.7",
"triple-beam": "^1.2.0"
}
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"yallist": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g=="
}
}
}
const jwt = require("jsonwebtoken");
const express = require("express");
const config = require("config");
const log = require("../utils/logger");
const authloginvalidation = require("../middleware/auth-login-validator");
const router = express.Router();
const jsonResponse = {};
router.post("/",authloginvalidation, async (req, res) => {
const ip = req.ip;
const token = jwt.sign({'ip':ip, 'identifier': req.body.name}, config.get('pkj'));
res.status(config.get('constants.HTTP_STATUS_CODE.OK')).json(token);
});
module.exports = router;
const express = require("express");
const router = express.Router();
const config = require("config");
const dbConn = require("../middleware/database");
const szerCampaniaValidator = require("../middleware/validation");
const log = require('../middleware/logger');
const dbConn = require("../utils/database");
const szerCampania= require("../classes/szerCampania");
const log = require('../utils/logger');
const auth_endpoint_validator = require('../middleware/auth-endpoint-validator');
const router = express.Router();
const jsonResponse = {};
dbConn.getConnection((err, connection) => {
......@@ -13,42 +14,43 @@ dbConn.getConnection((err, connection) => {
} else console.log("Conectado!...");
});
router.post("/obtener/contenido", (req, res) => {
const validateCampania = new szerCampaniaValidator();
//Si falta el parametro uid, error 400
var { error } = validateCampania.validate(req.body);
router.post("/obtener/contenido",auth_endpoint_validator, async (req, res) => {//Como segundo parametro puede ir una funcion middleware o un array de middlewares en el orden en que funcionan. //IMPLEMENTAR JWT
//Si parametro uid no cumple la validacion, error 400
var { error } = szerCampania.validate(req.body);
if (error) {
res
return res
.status(config.get("constants.HTTP_STATUS_CODE.BAD_REQUEST"))
.json({ error: error.details[0].message });
return;
;
}
//Seteo de UID ingresado en la peticion
let { uid } = req.body;
//seteo de objeto en base a modelo szerCampania
const campaniaObj = new szerCampania(req.body.uid);
//Seteo de entorno mediante userAgent
let isMobile = req.useragent.isMobile;
processHtml(res, uid, isMobile);
await processHtml(res, campaniaObj.uid, isMobile);
});
async function processHtml(res, uid, isMobile) {
//Buscar UID , si no esta es error 404
//console.log("obteniendo campaña asociada...");
try {
const campania = await getCampaniaById([uid]);
if (!campania || campania.length == 0) {
res
return res
.status(config.get("constants.HTTP_STATUS_CODE.NOT_FOUND"))
.json({ error: `El uid ${uid} no esta asociado a ninguna campaña.` });
return;
}
//console.log(campania[0].cam_id);
const template = await getTemplateById([campania[0].tem_id]);
if (!template || template.length == 0) {
res.status(config.get("constants.HTTP_STATUS_CODE.NOT_FOUND")).json({
return res.status(config.get("constants.HTTP_STATUS_CODE.NOT_FOUND")).json({
error: `La campaña uid ${uid} no tiene asociado ninguna plantilla de diseño.`,
});
return;
;
}
//console.log(template[0].tem_id);
......@@ -77,16 +79,9 @@ async function processHtml(res, uid, isMobile) {
jsonResponse.terminosCondiciones = generateHtmlCondiciones(campania);
res.status(config.get("constants.HTTP_STATUS_CODE.OK")).send(jsonResponse);
} catch (err) {
log.logger.error(`Error : ${err.message}`);
res
.status(config.get("constants.HTTP_STATUS_CODE.ERROR"))
.json({ error: `Ha ocurrido un error : ${err.message}` });
}
}
async function generateHtmlSection(campania, type, isMobile) {
try {
let contenidos = await getContenido(campania, type, isMobile, false);
let countContenido = await getContenido(campania, type, isMobile, true);
var posContenido = 0;
......@@ -125,10 +120,6 @@ async function generateHtmlSection(campania, type, isMobile) {
});
return arrayJson;
} catch (err) {
log.logger.error(`Error : ${err.message}`);
return [];
}
}
async function getContenido(campania, type, isMobile, isCount) {
......
const bcrypt = require("bcrypt");
const express = require("express");
const config = require("config");
const log = require('../utils/logger');
const router = express.Router();
const jsonResponse = {};
router.post("/" ,async (req, res) => {
const salt = await bcrypt.genSalt(10);
const bcryptpass = await bcrypt.hash(req.body.password, salt);
res.status(config.get('constants.HTTP_STATUS_CODE.OK')).json(bcryptpass);
});
module.exports = router;
\ No newline at end of file
const appRoot = require('app-root-path');
const winston = require('winston');
// Use JSON logging for log files
// Here winston.format.errors() just seem to work
// because there is no winston.format.simple()
const jsonLogFileFormat = winston.format.combine(
winston.format.errors({ stack: true }),
winston.format.timestamp(),
winston.format.prettyPrint(),
);
// Create file loggers
const logger = winston.createLogger({
level: 'debug',
format: jsonLogFileFormat,
transports: [
//
// - Write to all logs with level `info` and below to `combined.log`
// - Write all logs error (and below) to `error.log`.
//
new winston.transports.File({ filename: `${appRoot}/logs/error.log`, level: 'error' }),
new winston.transports.File({ filename: `${appRoot}/logs/app.log`, level: 'info' })
],
expressFormat: true,
});
module.exports.logger = logger;
\ No newline at end of file
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