Logged in and logged out at the same time when I close the website, using dashboards

Hello,

I am trying to create a simple log-in (without encryption and any recommendation of security, just testing the dashboards) using a MySQL database. The database has just one username and password to test it.

The idea of the log in is that when I open the web site, I just can see the log in Tab. When the user access with its username and password, this Tab is hidden, the rest of the Tabs of the application are shown and the user is redirected to one of the new Tabs allowed. Otherwise, when the new tabs appear, one of them has a button. It is a log out button. So when I press it, the web site goes back to the log in section, the log in Tab is shown and the rest of the Tabs are hidden. It works, as you can see here:


The problem is the following: if I log in and then I directly close the website, the next time I enter to the web page I'm in the log in Tab, but the Tabs shown are the ones that should appear when I am logged in. It's like if I was logged in and not at the same time:

Could you tell me how can I do to solve this problem? My first idea, if it's possible, is letting the user being logged in automatically, so it's logged out just when it presses the log out button.
The JSON is the following: [{"id":"246642f6.1782e6","type":"tab","label":"Flow Login","disabled":false,"info":""},{"id":"a4cbd3ca.8b92e","type":"ui_form","z":"246642f6.1782e6","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":70,"y":40,"wires":[["8203d26a.9b3d18"]]},{"id":"874b31d4.1d7af","type":"ui_ui_control","z":"246642f6.1782e6","name":"","events":"change","x":680,"y":320,"wires":[["7da6ec3d.ecefec","48c4af23.fa8798"]]},{"id":"c66ff645.86358","type":"function","z":"246642f6.1782e6","name":"","func":"\nreturn {\n payload:\n {\n \"tabs\":\n {\n \"show\": [\"Texto1\", \"Texto2\"],\n \"hide\": [\"Logueo\"],\n },\n }\n};","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":300,"wires":[["874b31d4.1d7af"]]},{"id":"7da6ec3d.ecefec","type":"ui_text","z":"246642f6.1782e6","group":"577d9561.0512a4","order":1,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":850,"y":200,"wires":[]},{"id":"48c4af23.fa8798","type":"ui_text","z":"246642f6.1782e6","group":"8fe01fb.69d976","order":0,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":850,"y":400,"wires":[]},{"id":"e57bc7cf.57163","type":"ui_button","z":"246642f6.1782e6","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":230,"y":500,"wires":[["2586718f.8a6e5e","6b047171.c11a8"]]},{"id":"2586718f.8a6e5e","type":"function","z":"246642f6.1782e6","name":"","func":"\nreturn {\n payload:\n {\n \"tabs\":\n {\n \"hide\": [\"Texto1\", \"Texto2\"],\n \"show\": [\"Logueo\"],\n },\n }\n};","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":540,"wires":[["874b31d4.1d7af"]]},{"id":"8203d26a.9b3d18","type":"function","z":"246642f6.1782e6","name":"SELECT Data","func":"msg.topic= \"SELECT * FROM Usuario WHERE Usuario='\"+msg.payload.user+\"' AND Pass='\"+msg.payload.pass+\"'\";\n//msg.topic= 'SELECT * FROM Usuario';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":140,"y":100,"wires":[["cd3e90d9.d127"]]},{"id":"cd3e90d9.d127","type":"mysql","z":"246642f6.1782e6","mydb":"ab316cb2.9457f","name":"Usuarios Database","x":210,"y":160,"wires":[["4482cadc.51c89c"]]},{"id":"4482cadc.51c89c","type":"switch","z":"246642f6.1782e6","name":"","property":"payload.length","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":220,"wires":[["f7ef16e9.edee78"],["c66ff645.86358","8f770a35.beb008"]]},{"id":"f7ef16e9.edee78","type":"change","z":"246642f6.1782e6","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":480,"y":160,"wires":[[]]},{"id":"8f770a35.beb008","type":"change","z":"246642f6.1782e6","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Texto1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":260,"wires":[["874b31d4.1d7af"]]},{"id":"6b047171.c11a8","type":"change","z":"246642f6.1782e6","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Logueo","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":480,"wires":[["874b31d4.1d7af"]]},{"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":"ab316cb2.9457f","type":"MySQLdatabase","name":"","host":"127.0.0.1","port":"3306","db":"Usuarios_Prueba","tz":"","charset":"UTF8"},{"id":"e372f103.a993d","type":"ui_tab","name":"Logueo","icon":"dashboard","order":1,"disabled":false,"hidden":false},{"id":"20e98d46.c760ba","type":"ui_tab","name":"Texto1","icon":"dashboard","order":2,"disabled":false,"hidden":true},{"id":"965580ca.778f48","type":"ui_tab","name":"Texto2","icon":"dashboard","order":3,"disabled":false,"hidden":true}]

I have also uploaded a screenshot of the MySQL database to let you create the database and test it.

Best Regards,
Franco

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