From 52fad1dd43980522e24b513fc267205b27137b78 Mon Sep 17 00:00:00 2001 From: Pablinux Date: Sat, 13 Jul 2024 01:41:36 -0500 Subject: [PATCH] CORRECCION 3 --- src/controladores/controlador_General.js | 51 +++++++++++++----------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/controladores/controlador_General.js b/src/controladores/controlador_General.js index d69dece..fe84796 100644 --- a/src/controladores/controlador_General.js +++ b/src/controladores/controlador_General.js @@ -35,28 +35,33 @@ controlador.auth_redirect = (req, res) => { controlador.auth = (req, res) => { console.log(req.body); - var pwd = stringTo_md5(req.body.password); - req.getConnection((error, conn, next) => { - conn.query(`SELECT * FROM usuarios WHERE n_sesion = ? and clave=?`, [req.body.usuario, pwd], (err, rows) => { - if (err) { - //res.json(err); - res.json("No Autorizado"); - } else { - try { - if (rows.length > 0) { - //res.json({sision:"exitosa"}); + if (req.body.password !== "") { + var pwd = stringTo_md5(req.body.password); + req.getConnection((error, conn, next) => { + conn.query(`SELECT * FROM usuarios WHERE n_sesion = ? and clave=?`, [req.body.usuario, pwd], (err, rows) => { + if (err) { + //res.json(err); + res.json("No Autorizado"); + } else { + try { + if (rows.length > 0) { + //res.json({sision:"exitosa"}); - console.log(rows); - res.render('app_pedidos'); + console.log(rows); + res.render('app_pedidos'); + } + } catch (e) { + res.render('login'); + next(); } - } catch (e) { - res.render('login'); - //next(); } - } + }); + //conn.end(); }); - //conn.end(); - }); + } else { + res.render('login'); + next(); + } //res.render(''); }; @@ -82,7 +87,7 @@ controlador.login_test = (req, res) => { res.render('login_test'); }; -var sesion_login = {"UID":"","SESSION":"","KEY":""}; +var sesion_login = { "UID": "", "SESSION": "", "KEY": "" }; //************* GENERA TOKENS ****************// controlador.auth_keygen = async (req, res) => { var datUsr = base64decode(req.body.data); @@ -127,7 +132,7 @@ controlador.auth_token = async (req, res) => { if (!token) { return res.status(401).json({ auth: false, message: 'No token provided' }); } - try{ + try { await req.getConnection(async (error, conn, next) => { //var key = await keygen(conn); var decoded = jwt.verify(token, config.secret.key); @@ -135,9 +140,9 @@ controlador.auth_token = async (req, res) => { sesion_login.UID = idUnico; res.json(sesion_login); }); - - }catch(err){ - res.json({ auth: false, message: 'Unauthorized: '+err.message }); + + } catch (err) { + res.json({ auth: false, message: 'Unauthorized: ' + err.message }); } };