Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post("/loggin", (req, res) => {
- console.log(req.body.password);
- console.log(req.body.name);
- const name = req.body.name;
- const password = req.body.password;
- MongoClient.connect(url, function(err, db) {
- console.log(1);
- if (err) throw err;
- const dbo = db.db("tareas");
- dbo
- .collection("usuario")
- .find({ nombre: name, password })
- .toArray(function(err, usuarios) {
- console.log(2);
- if (err) throw err;
- console.log(usuarios);
- if (usuarios.length > 0) {
- var x;
- dbo
- .collection("usuario_rol")
- .find({ "_id.id_usuario": usuarios[0]._id })
- .toArray(function(err, usuarios_rol) {
- if (err) throw err;
- var idroles = [];
- for (x = 0; x < usuarios_rol.length; x++) {
- idroles.push(usuarios_rol[x]._id.id_rol);
- }
- console.log(idroles);
- dbo
- .collection("rol_funcion")
- .find({ "_id.id_rol": { $in: idroles } })
- .toArray(function(err, roles_fun) {
- if (err) throw err;
- var idfunciones = [];
- console.log(roles_fun);
- for (x = 0; x < roles_fun.length; x++) {
- idfunciones.push(roles_fun[x]._id.id_funcion);
- }
- dbo
- .collection("funcion_iu")
- .find({ "_id.id_funcion": { $in: idfunciones } })
- .toArray(function(err, fun_iu) {
- if (err) throw err;
- var idius = [];
- for (x = 0; x < fun_iu.length; x++) {
- idius.push(fun_iu[x]._id.id_iu);
- }
- dbo
- .collection("iu")
- .find({ _id: { $in: idius } })
- .toArray(function(err, ius) {
- if (err) throw err;
- res.render("user", {
- usuario: usuarios[0],
- interfaces: ius
- });
- });
- });
- });
- });
- } else res.redirect("/");
- db.close();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment