pacha2880

Untitled

Jun 16th, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. router.post("/loggin", (req, res) => {
  2.   console.log(req.body.password);
  3.   console.log(req.body.name);
  4.   const name = req.body.name;
  5.   const password = req.body.password;
  6.   MongoClient.connect(url, function(err, db) {
  7.     console.log(1);
  8.     if (err) throw err;
  9.     const dbo = db.db("tareas");
  10.     dbo
  11.       .collection("usuario")
  12.       .find({ nombre: name, password })
  13.       .toArray(function(err, usuarios) {
  14.         console.log(2);
  15.         if (err) throw err;
  16.         console.log(usuarios);
  17.         if (usuarios.length > 0) {
  18.           var x;
  19.           dbo
  20.             .collection("usuario_rol")
  21.             .find({ "_id.id_usuario": usuarios[0]._id })
  22.             .toArray(function(err, usuarios_rol) {
  23.               if (err) throw err;
  24.               var idroles = [];
  25.               for (x = 0; x < usuarios_rol.length; x++) {
  26.                 idroles.push(usuarios_rol[x]._id.id_rol);
  27.               }
  28.               console.log(idroles);
  29.               dbo
  30.                 .collection("rol_funcion")
  31.                 .find({ "_id.id_rol": { $in: idroles } })
  32.                 .toArray(function(err, roles_fun) {
  33.                   if (err) throw err;
  34.                   var idfunciones = [];
  35.                   console.log(roles_fun);
  36.                   for (x = 0; x < roles_fun.length; x++) {
  37.                     idfunciones.push(roles_fun[x]._id.id_funcion);
  38.                   }
  39.                   dbo
  40.                     .collection("funcion_iu")
  41.                     .find({ "_id.id_funcion": { $in: idfunciones } })
  42.                     .toArray(function(err, fun_iu) {
  43.                       if (err) throw err;
  44.                       var idius = [];
  45.                       for (x = 0; x < fun_iu.length; x++) {
  46.                         idius.push(fun_iu[x]._id.id_iu);
  47.                       }
  48.                       dbo
  49.                         .collection("iu")
  50.                         .find({ _id: { $in: idius } })
  51.                         .toArray(function(err, ius) {
  52.                           if (err) throw err;
  53.                           res.render("user", {
  54.                             usuario: usuarios[0],
  55.                             interfaces: ius
  56.                           });
  57.                         });
  58.                     });
  59.                 });
  60.             });
  61.         } else res.redirect("/");
  62.         db.close();
  63.       });
  64.   });
Advertisement
Add Comment
Please, Sign In to add comment