Logic Machine Forum
User Profile - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: User Profile (/showthread.php?tid=2679)



User Profile - sjfp - 09.06.2020

Is there a way to determine which user has logged on to the LM.
Would like to change the value of an Object to identify which user is logged in, so that various controls can be set to Read-Only depending on which user has logged on.
I have a script that enable and disable objects, so just need the bit to find the user ?
Thanks for help
engineer1 grp.write('1/1/1',1)
engineer2 grp.write('1/1/1',2)


RE: User Profile - Erwin van der Zwart - 09.06.2020

Hi,

Run this script to create the user.lp inside the user ftp folder:
Code:
-- use this path for request: http://192.168.0.10/user/user.lp
-- make sure to enable password for the user folder in the user access settings otherwise it shows 'anonymous'

dst = '/www/user/user.lp'
io.writefile(dst, [[
<?
   require('apps')
   clientuser = request.username or 'anonymous'
   print(clientuser)
?>
]])
script.disable(_SCRIPTNAME)
Then use this in your custom JS to fetched the logged in user:
Code:
$(function(){
   $.get("/user/user.lp", function(data, status){
      if (status === "success"){
         var currentuser = data.trim()
         if(currentuser === 'admin'){
          // do action for admin
         }else if(currentuser === 'erwin'){
            // do action for erwin
        }
       }
   });
})
BR,

Erwin


RE: User Profile - sjfp - 09.06.2020

Thank You very much, will give it a try


RE: User Profile - Daniel - 09.06.2020

In the new FW we can check current user by Globals.user
No need for lp in this case. It will work only in RC2 or the new 2.5.0 for SE

Code:
$(function() {   
      var currentuser = Globals.user
      if(currentuser === 'admin'){
       // do action for admin
      }else if(currentuser === 'erwin'){
       // do action for erwin
      }
});



RE: User Profile - Erwin van der Zwart - 09.06.2020

Yep, noticed it in the beta, cool (:


RE: User Profile - sjfp - 09.06.2020

Cool, how can I display the logged in user name on the main Vis page


RE: User Profile - Daniel - 09.06.2020

write it to the object


RE: User Profile - admin - 09.06.2020

Create a label element, set additional classes to username
Add to Custom JS:
Code:
$(function(){
  $('.username').text(Globals.user);
});



RE: User Profile - sjfp - 09.06.2020

So easy when you know how.
Thanks again for your continued support


RE: User Profile - toujour - 13.08.2020

How can I log the actual user in the "objects log" ?
I want recording the user that had pressed the button.


RE: User Profile - Daniel - 13.08.2020

In latest fw it is done out of the box


RE: User Profile - toujour - 13.08.2020

ok....now I saw !!
thanks !!