Detect automatically user enter UI

Hello,

I need to detect when the user enters to the /ui, to send in that moment a msg through some nodes. I tried to do it using a http in node, but it did not work. What can I do to solve this?

Regards,
Franco

The ui_control node will tell you whenever a connection is made to the dashboard.

1 Like

Hello Colin,
Thanks for your answer. After doing some tests, I did it and it worked. The main problem now is that I need to move the user from one Tab to another when the application detects the user enters to the ui website. If I do it inmediatly after the user enters to the website, it doesn't work beause it has to wait until the website loads.

To solve it, I manually put a Delay node between the ui_control node and the rest of the nodes. So, the application waits a bit of time until the web site loads.

Do you know how can I do this automatically, instead of calculating by hand when the user enters to the website? This worked, but it's not a good solution setting manually when the application loads the full website.

If you want it, I can show you the JSON of the solution that I have done.

Regards,
Franco

Can you post ui_control node and other associated nodes that you tried did not work? Mark the nodes and use the menu Export feature to copy to clipboard then paste it here. See this post for more details - How to share code or flow json

Hello Colin,
Thank you for your answer. The json is the following:

[{"id":"f81a9ef.47d3f6","type":"subflow","name":"Ecripcion pwd","info":"","category":"","in":[{"x":100,"y":100,"wires":[{"id":"443a4497.84fe94"},{"id":"48bd434e.d73a8c"}]}],"out":[{"x":600,"y":160,"wires":[{"id":"eb58f019.212078","port":0}]}],"env":[],"color":"#DDAA99"},{"id":"443a4497.84fe94","type":"function","z":"f81a9ef.47d3f6","name":"","func":"usuario = msg.payload.user;\nreturn {payload: {\n    user: usuario\n}};","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":100,"wires":[["eb58f019.212078"]]},{"id":"48bd434e.d73a8c","type":"function","z":"f81a9ef.47d3f6","name":"","func":"msg.payload = msg.payload.pass;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":220,"y":180,"wires":[["1a0489a9.6a59d6"]]},{"id":"9e742215.9342a8","type":"function","z":"f81a9ef.47d3f6","name":"","func":"clave = msg.payload;\nreturn {payload: {\n    pass: clave\n}};","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":260,"wires":[["eb58f019.212078"]]},{"id":"eb58f019.212078","type":"join","z":"f81a9ef.47d3f6","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":490,"y":160,"wires":[[]]},{"id":"1a0489a9.6a59d6","type":"hmac","z":"f81a9ef.47d3f6","name":"Cifrado Password","algorithm":"HmacSHA256","key":"hidroponia","x":310,"y":220,"wires":[["9e742215.9342a8"]]},{"id":"546e95fe.84a464","type":"subflow","name":"Revision DB","info":"","category":"","in":[{"x":40,"y":80,"wires":[{"id":"b31fae98.c8c2b8"}]}],"out":[{"x":400,"y":100,"wires":[{"id":"1eee9a01.46475e","port":0}]},{"x":400,"y":180,"wires":[{"id":"1eee9a01.46475e","port":1}]}],"env":[],"color":"#DDAA99"},{"id":"b31fae98.c8c2b8","type":"mysql","z":"546e95fe.84a464","mydb":"ab316cb2.9457f","name":"Usuarios Database","x":190,"y":80,"wires":[["1eee9a01.46475e"]]},{"id":"1eee9a01.46475e","type":"switch","z":"546e95fe.84a464","name":"","property":"payload.length","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":250,"y":140,"wires":[[],[]]},{"id":"ab316cb2.9457f","type":"MySQLdatabase","name":"","host":"127.0.0.1","port":"3306","db":"Usuarios_Prueba","tz":"","charset":"UTF8"},{"id":"172f986a.2b1cf","type":"tab","label":"Flow Login","disabled":false,"info":""},{"id":"1c791026.2db35","type":"ui_form","z":"172f986a.2b1cf","name":"","label":"Log in","group":"e84c813c.e2e36","order":1,"width":0,"height":0,"options":[{"label":"Usuario:","value":"user","type":"text","required":true,"rows":null},{"label":"Contraseña:","value":"pass","type":"password","required":true,"rows":null}],"formValue":{"user":"","pass":""},"payload":"","submit":"submit","cancel":"cancel","topic":"login","x":90,"y":40,"wires":[["6914d98.2b48d28"]]},{"id":"4a5f285e.cb551","type":"ui_ui_control","z":"172f986a.2b1cf","name":"","events":"change","x":820,"y":280,"wires":[["390f37fb.18fad8","cc37cdbf.1f1488"]]},{"id":"d308f953.a1b428","type":"function","z":"172f986a.2b1cf","name":"","func":"flow.set('logueado', true);\nreturn {\n payload:\n {\n \"tabs\":\n {\n \"show\": [\"Texto1\", \"Texto2\"],\n \"hide\": [\"Loguearse\", \"Registrarse\"],\n },\n }\n};","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":260,"wires":[["4a5f285e.cb551"]]},{"id":"390f37fb.18fad8","type":"ui_text","z":"172f986a.2b1cf","group":"577d9561.0512a4","order":1,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":970,"y":240,"wires":[]},{"id":"cc37cdbf.1f1488","type":"ui_text","z":"172f986a.2b1cf","group":"8fe01fb.69d976","order":0,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":970,"y":300,"wires":[]},{"id":"8d7aa7c9.5444c8","type":"ui_button","z":"172f986a.2b1cf","name":"","group":"577d9561.0512a4","order":2,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"Presionado","payloadType":"str","topic":"Button","x":50,"y":560,"wires":[["29fa2dee.c60d0a"]]},{"id":"e1cbbe61.f5c47","type":"function","z":"172f986a.2b1cf","name":"","func":"flow.set('logueado', false);\nreturn {\n payload:\n {\n \"tabs\":\n {\n \"hide\": [\"Texto1\", \"Texto2\"],\n \"show\": [\"Loguearse\", \"Registrarse\"],\n },\n }\n};","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":320,"wires":[["4a5f285e.cb551"]]},{"id":"ed861367.c0ae58","type":"change","z":"172f986a.2b1cf","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Usuario y/o contraseña no valido","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":120,"wires":[[]]},{"id":"9468a93c.9d7f18","type":"change","z":"172f986a.2b1cf","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Texto1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":220,"wires":[["4a5f285e.cb551"]]},{"id":"f86dc3da.f170f","type":"change","z":"172f986a.2b1cf","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Loguearse","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":360,"wires":[["4a5f285e.cb551"]]},{"id":"e7538bde.c85dc","type":"ui_form","z":"172f986a.2b1cf","name":"","label":"Registrarse","group":"8820212b.553898","order":1,"width":0,"height":0,"options":[{"label":"Usuario:","value":"user","type":"text","required":true,"rows":null},{"label":"Contraseña:","value":"pass","type":"password","required":true,"rows":null}],"formValue":{"user":"","pass":""},"payload":"","submit":"submit","cancel":"cancel","topic":"registrarse","x":110,"y":600,"wires":[["94b060fa.5ca2c"]]},{"id":"1f89ed21.9ad2ab","type":"change","z":"172f986a.2b1cf","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Usuario registrado","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":580,"wires":[["8a942c17.532f9"]]},{"id":"8a942c17.532f9","type":"ui_text","z":"172f986a.2b1cf","group":"8820212b.553898","order":1,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":810,"y":660,"wires":[]},{"id":"69679d49.8e87a4","type":"subflow:546e95fe.84a464","z":"172f986a.2b1cf","name":"","env":[],"x":230,"y":160,"wires":[["ed861367.c0ae58"],["af3db871.7a757"]]},{"id":"193b3d7.0a27443","type":"subflow:546e95fe.84a464","z":"172f986a.2b1cf","name":"","x":150,"y":720,"wires":[["650a835e.d16b2c"],["e2de8543.b71c3"]]},{"id":"e2de8543.b71c3","type":"change","z":"172f986a.2b1cf","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Este usuario ya existe","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":740,"wires":[["8a942c17.532f9"]]},{"id":"2af25309.068464","type":"function","z":"172f986a.2b1cf","name":"","func":"flow.set('usuario', msg.payload.user);\nflow.set('pass', msg.payload.pass);\n\nmsg.topic= \"SELECT * FROM Usuario WHERE Usuario='\"+msg.payload.user+\"'\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":100,"y":680,"wires":[["193b3d7.0a27443"]]},{"id":"650a835e.d16b2c","type":"function","z":"172f986a.2b1cf","name":"Agregar DB","func":"msg.topic= \"INSERT INTO Usuario (Usuario, Pass) VALUES ('\"+flow.get('usuario')+\"', '\"+flow.get('pass')+\"')\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":330,"y":680,"wires":[["8ef19b72.94d458"]]},{"id":"8ef19b72.94d458","type":"mysql","z":"172f986a.2b1cf","mydb":"ab316cb2.9457f","name":"Usuarios Database","x":410,"y":620,"wires":[["1f89ed21.9ad2ab"]]},{"id":"60812495.c65d4c","type":"function","z":"172f986a.2b1cf","name":"Acceso DB","func":"flow.set('usuario', msg.payload.user);\n\nmsg.topic= \"SELECT * FROM Usuario WHERE Usuario='\"+msg.payload.user+\"' AND Pass='\"+msg.payload.pass+\"'\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":190,"y":120,"wires":[["69679d49.8e87a4"]]},{"id":"94b060fa.5ca2c","type":"subflow:f81a9ef.47d3f6","z":"172f986a.2b1cf","name":"","x":120,"y":640,"wires":[["2af25309.068464"]]},{"id":"6914d98.2b48d28","type":"subflow:f81a9ef.47d3f6","z":"172f986a.2b1cf","name":"","env":[],"x":140,"y":80,"wires":[["60812495.c65d4c"]]},{"id":"7d418f6c.b02d28","type":"mysql","z":"172f986a.2b1cf","mydb":"ab316cb2.9457f","name":"Usuarios Database","x":410,"y":240,"wires":[["9468a93c.9d7f18","d308f953.a1b428"]]},{"id":"af3db871.7a757","type":"function","z":"172f986a.2b1cf","name":"Usuario Accedido","func":"msg.topic= \"UPDATE Usuario SET Ingresado = true WHERE Usuario='\"+flow.get('usuario')+\"'\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":200,"wires":[["7d418f6c.b02d28"]]},{"id":"ad651d69.7002a8","type":"function","z":"172f986a.2b1cf","name":"Cerrar sesión de usuario","func":"msg.topic= \"UPDATE Usuario SET Ingresado=false WHERE Usuario='\"+msg.payload[0].Usuario+\"'\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":350,"y":440,"wires":[["8271c6f9.95b398","e1cbbe61.f5c47"]]},{"id":"8271c6f9.95b398","type":"mysql","z":"172f986a.2b1cf","mydb":"ab316cb2.9457f","name":"Usuarios Database","x":510,"y":480,"wires":[["f86dc3da.f170f"]]},{"id":"f9e15495.61f668","type":"function","z":"172f986a.2b1cf","name":"Acceso DB","func":"msg.topic= \"SELECT * FROM Usuario WHERE Ingresado = true\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":310,"y":300,"wires":[["f665a54a.a90f2"]]},{"id":"f665a54a.a90f2","type":"subflow:546e95fe.84a464","z":"172f986a.2b1cf","name":"","env":[],"x":370,"y":340,"wires":[["e1cbbe61.f5c47","f86dc3da.f170f"],["9468a93c.9d7f18","d308f953.a1b428"]]},{"id":"29fa2dee.c60d0a","type":"function","z":"172f986a.2b1cf","name":"Acceso DB","func":"msg.topic= \"SELECT * FROM Usuario WHERE Ingresado = true\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":110,"y":520,"wires":[["bfb26073.531ef8"]]},{"id":"bfb26073.531ef8","type":"mysql","z":"172f986a.2b1cf","mydb":"ab316cb2.9457f","name":"Usuarios Database","x":150,"y":480,"wires":[["ad651d69.7002a8","6a6a92f7.53ee0c"]]},{"id":"6a6a92f7.53ee0c","type":"debug","z":"172f986a.2b1cf","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":300,"y":540,"wires":[]},{"id":"bf57134f.e24458","type":"function","z":"172f986a.2b1cf","name":"","func":"msg={\n  topic: \"control\",\n  payload: \"close\"\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":180,"y":260,"wires":[["f9e15495.61f668"]]},{"id":"96d5e88a.79e6b8","type":"ui_ui_control","z":"172f986a.2b1cf","name":"","events":"connect","x":60,"y":340,"wires":[["5f42612c.8c0898","67af2d54.a0ea64"]]},{"id":"67af2d54.a0ea64","type":"debug","z":"172f986a.2b1cf","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":190,"y":380,"wires":[]},{"id":"5f42612c.8c0898","type":"delay","z":"172f986a.2b1cf","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":120,"y":300,"wires":[["bf57134f.e24458"]]},{"id":"e84c813c.e2e36","type":"ui_group","name":"Group 1","tab":"e372f103.a993d","order":1,"disp":true,"width":6},{"id":"577d9561.0512a4","type":"ui_group","name":"Group 1","tab":"20e98d46.c760ba","order":1,"disp":true,"width":6},{"id":"8fe01fb.69d976","type":"ui_group","name":"Group 1","tab":"965580ca.778f48","order":1,"disp":true,"width":6},{"id":"8820212b.553898","type":"ui_group","name":"Group 1","tab":"3fb7634b.037494","order":1,"disp":true,"width":"6","collapse":false},{"id":"e372f103.a993d","type":"ui_tab","name":"Loguearse","icon":"dashboard","order":1,"disabled":false,"hidden":false},{"id":"20e98d46.c760ba","type":"ui_tab","name":"Texto1","icon":"dashboard","order":3,"disabled":false,"hidden":true},{"id":"965580ca.778f48","type":"ui_tab","name":"Texto2","icon":"dashboard","order":4,"disabled":false,"hidden":true},{"id":"3fb7634b.037494","type":"ui_tab","name":"Registrarse","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

I don't know if it takes into account the subflows I have created for this solution. If it does not considered them, please let me know it.
The database I used for this solution has the following information (the flows were created to let you register a new user in the database):

Thanks & Regards,
Franco

Hello Collin,

I have tried to import what I have done, and it doesn't import the subnode Encripcion pwd. It has the following:

The code inside the different functions is the following:
Extraer usuario:

usuario = msg.payload.user;
return {payload: {
    user: usuario
}};

Extraer password:

msg.payload = msg.payload.pass;
return msg;

Convertir msg a objeto:

clave = msg.payload;
return {payload: {
    pass: clave
}};

Cifrado password was configured with the following:


And finally, the join node was configured like this:

Thanks & Regards,
Franco

Obviously there is no way I can run that flow it is much too complex.

Can you explain what you mean by that?

I want to do a log in, with the particularity that if the user was logged in and closed the website without logging out, using the button which appears in the Tab "Texto 1", then if it opens the web site again it has to be logged in.
At first, the problem here was that when I close the website and open it again, if the user had logged in and then closed the website, it appears the tab to write the user and password and the Tabs available were "Texto 1" and "Texto 2" (like if it was logged in and not at the same time). To solve this, I put a column in the database that checks if a user was logged in. So, when I enter to the website, with a UI control node I check this information in the databse. If it works, the user is logged in and it appears the tabs that have to appear when the user is logged in. If it doesn't work, just appear the Tabs to log in or register a new user.
This last solution worked, but the problem is that I cannot redirect the user to the log in Tab or the "Texto 1" tab unless the web site finishes loading succesfully. The main problem with this solution is that the time needed to load successfully the website depends on the user's connectivity, so I cannot put a delay node to make it manually wait X seconds until the website loads successfully to check if a user was logged in previously or not

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.