CORRECCION 3

This commit is contained in:
Pablinux
2024-07-13 01:41:36 -05:00
parent 97f4f3a488
commit 52fad1dd43

View File

@@ -35,28 +35,33 @@ controlador.auth_redirect = (req, res) => {
controlador.auth = (req, res) => { controlador.auth = (req, res) => {
console.log(req.body); console.log(req.body);
var pwd = stringTo_md5(req.body.password); if (req.body.password !== "") {
req.getConnection((error, conn, next) => { var pwd = stringTo_md5(req.body.password);
conn.query(`SELECT * FROM usuarios WHERE n_sesion = ? and clave=?`, [req.body.usuario, pwd], (err, rows) => { req.getConnection((error, conn, next) => {
if (err) { conn.query(`SELECT * FROM usuarios WHERE n_sesion = ? and clave=?`, [req.body.usuario, pwd], (err, rows) => {
//res.json(err); if (err) {
res.json("No Autorizado"); //res.json(err);
} else { res.json("No Autorizado");
try { } else {
if (rows.length > 0) { try {
//res.json({sision:"exitosa"}); if (rows.length > 0) {
//res.json({sision:"exitosa"});
console.log(rows); console.log(rows);
res.render('app_pedidos'); 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(''); //res.render('');
}; };
@@ -82,7 +87,7 @@ controlador.login_test = (req, res) => {
res.render('login_test'); res.render('login_test');
}; };
var sesion_login = {"UID":"","SESSION":"","KEY":""}; var sesion_login = { "UID": "", "SESSION": "", "KEY": "" };
//************* GENERA TOKENS ****************// //************* GENERA TOKENS ****************//
controlador.auth_keygen = async (req, res) => { controlador.auth_keygen = async (req, res) => {
var datUsr = base64decode(req.body.data); var datUsr = base64decode(req.body.data);
@@ -127,7 +132,7 @@ controlador.auth_token = async (req, res) => {
if (!token) { if (!token) {
return res.status(401).json({ auth: false, message: 'No token provided' }); return res.status(401).json({ auth: false, message: 'No token provided' });
} }
try{ try {
await req.getConnection(async (error, conn, next) => { await req.getConnection(async (error, conn, next) => {
//var key = await keygen(conn); //var key = await keygen(conn);
var decoded = jwt.verify(token, config.secret.key); var decoded = jwt.verify(token, config.secret.key);
@@ -136,8 +141,8 @@ controlador.auth_token = async (req, res) => {
res.json(sesion_login); res.json(sesion_login);
}); });
}catch(err){ } catch (err) {
res.json({ auth: false, message: 'Unauthorized: '+err.message }); res.json({ auth: false, message: 'Unauthorized: ' + err.message });
} }
}; };