Commit db7bae23 by Denys Tito Urbano

Parametros cambiados para el login

parent 3e8cac99
File added
...@@ -7,8 +7,9 @@ DRIVE_ACCOUNT=materiales@sacooliveros.edu.pe ...@@ -7,8 +7,9 @@ DRIVE_ACCOUNT=materiales@sacooliveros.edu.pe
DB_POSTGRESQL_SIIAA_HOST=162.0.227.166 DB_POSTGRESQL_SIIAA_HOST=162.0.227.166
DB_POSTGRESQL_SIIAA_PORT=5434 DB_POSTGRESQL_SIIAA_PORT=5434
DB_POSTGRESQL_SIIAA_NAME=db_sis_siiaa_mig DB_POSTGRESQL_SIIAA_NAME=db_sis_siiaa_mig
DB_POSTGRESQL_SIIAA_USERNAME=usr_soporte DB_POSTGRESQL_SIIAA_USERNAME=usr_trismegisto
DB_POSTGRESQL_SIIAA_PASSWORD=s@c00504+ DB_POSTGRESQL_SIIAA_PASSWORD=S@c0+180405$
URL_FACTURACION_ELECTRONICA_SIIAA=https://fichaonline.sacooliveros.edu.pe:8080/FacturacionElectronicaSIIAA/api/v1 URL_FACTURACION_ELECTRONICA_SIIAA=https://fichaonline.sacooliveros.edu.pe:8080/FacturacionElectronicaSIIAA/api/v1
URL_TRISMEGISTO_APIS=https://fichaonline.sacooliveros.edu.pe:8000/trismegisto-apis/api/v1 URL_TRISMEGISTO_APIS=https://fichaonline.sacooliveros.edu.pe:8000/trismegisto-apis/api/v1
\ No newline at end of file URL_SO_API_NOTIFICATION=https://fichaonline.sacooliveros.edu.pe:8000/so-api-notification/poqh/so-api-notification
\ No newline at end of file
...@@ -16,6 +16,18 @@ const post_login = async (req, res) => { ...@@ -16,6 +16,18 @@ const post_login = async (req, res) => {
} }
}; };
const post_generar_usuario = async (req, res) => {
try {
const { tipo_operacion, correo, perfil } = req.body;
const salida = await service.post_generar_usuario({ tipo_operacion, correo, perfil });
const { json } = salida;
res.json(json);
} catch (error) {
res.status(400).json(error_json(error.message));
}
};
const get_account = async (req, res) => { const get_account = async (req, res) => {
try { try {
const { documento } = req.params; const { documento } = req.params;
...@@ -30,5 +42,6 @@ const get_account = async (req, res) => { ...@@ -30,5 +42,6 @@ const get_account = async (req, res) => {
module.exports = { module.exports = {
post_login, post_login,
post_generar_usuario,
get_account get_account
}; };
\ No newline at end of file
const { default: axios } = require('axios');
const { encrypt } = require('../helpers/encrypt'); const { encrypt } = require('../helpers/encrypt');
const connection = require('./config'); const connection = require('./config');
...@@ -5,17 +6,44 @@ const post_login = async ({ email, password }) => { ...@@ -5,17 +6,44 @@ const post_login = async ({ email, password }) => {
if (password) { if (password) {
const password_encrypt = encrypt(password); const password_encrypt = encrypt(password);
return await connection.oneOrNone('SELECT * FROM academico.func_tma_login_obtener ( $1, $2 );', [email, password_encrypt]); return await connection.oneOrNone('SELECT * FROM academico.func_tma_login_obtener_v2 ( $1, $2 );', [email, password_encrypt]);
} else { } else {
return await connection.oneOrNone('SELECT * FROM academico.func_tma_login_obtener ( $1 );', [email]); return await connection.oneOrNone('SELECT * FROM academico.func_tma_login_obtener ( $1 );', [email]);
} }
}; };
const post_generar_usuario = async ({ tipo_operacion, correo, perfil }) => {
const contrasenia = `Saco+${Math.floor(10000 + (Math.random() * 99999))}`;
const contrasenia_encriptada = encrypt(contrasenia);
const response = await connection.oneOrNone('SELECT * FROM seguridad.func_usuario_actualizar ( $1 );', [{ tipo_operacion, correo, contrasenia_encriptada, perfil }]);
const usuario_login = response.json.data["usuario_login"];
const response_2 = await connection.oneOrNone('SELECT * FROM seguridad.func_usuario_listar ( $1 );', [{
tipo_operacion: "plantilla_html_tutor_profesor",
correo_destinatario: correo,
usuario_login,
usuario_contrasenia: contrasenia,
plataforma_nombre: "TMA"
}]);
const remitente = response_2.json.data["correo_remitente"];
const destinatario = response_2.json.data["correo_destinatario"];
const asunto = response_2.json.data["correo_asunto"];
const mensaje = response_2.json.data["correo_mensaje"];
const url_enviar_correo = `${process.env.URL_SO_API_NOTIFICATION}/notification/sends/many`;
const response_3 = await axios.post(url_enviar_correo, { fromEmail: remitente, toEmails: ["dtito.ti@sacooliveros.edu.pe"], subject: asunto, mailContent: mensaje });
return response;
};
const get_account = async ({ documento }) => { const get_account = async ({ documento }) => {
return await connection.oneOrNone('SELECT * FROM academico.func_tma_cuenta_obtener ( $1 );', [documento]); return await connection.oneOrNone('SELECT * FROM academico.func_tma_cuenta_obtener_v2 ( $1 );', [documento]);
}; };
module.exports = { module.exports = {
post_login, post_login,
post_generar_usuario,
get_account get_account
}; };
\ No newline at end of file
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const { check } = require('express-validator'); const { check } = require('express-validator');
const { post_login, get_account } = require('../controllers/auth.controller'); const { post_login, post_generar_usuario, get_account } = require('../controllers/auth.controller');
const { validate_errors, validate_jwt } = require('../middlewares'); const { validate_errors, validate_jwt } = require('../middlewares');
router.post('/login', router.post('/login',
...@@ -10,6 +10,12 @@ router.post('/login', ...@@ -10,6 +10,12 @@ router.post('/login',
validate_errors, validate_errors,
post_login); post_login);
router.post('/generar_usuario',
check('correo', 'Correo inválido').not().isEmpty(),
check('perfil', 'Perfil inválido').not().isEmpty(),
validate_errors,
post_generar_usuario);
router.get('/account', router.get('/account',
validate_jwt, validate_jwt,
get_account); get_account);
......
...@@ -4,11 +4,16 @@ const post_login = async (input) => { ...@@ -4,11 +4,16 @@ const post_login = async (input) => {
return await db.post_login(input); return await db.post_login(input);
}; };
const post_generar_usuario = async (input) => {
return await db.post_generar_usuario(input);
};
const get_account = async (input) => { const get_account = async (input) => {
return await db.get_account(input); return await db.get_account(input);
}; };
module.exports = { module.exports = {
post_login, post_login,
post_generar_usuario,
get_account get_account
}; };
\ 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