Logic Machine Forum
Username in visu - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Visualization (https://forum.logicmachine.net/forumdisplay.php?fid=9)
+--- Thread: Username in visu (/showthread.php?tid=1044)



Username in visu - Thomas - 16.10.2017

Hi
Can I show name of the actually logged on user in my visu?
Do you have javascript/css etc which does this function?
Thank you


RE: Username in visu - Erwin van der Zwart - 16.10.2017

Hi,

Only solution i know is by using a .lp file (in sample i named it user.lp) with this content:
Code:
<?
    require('apps')
    clientuser = request.username or 'anonymous'
    print(clientuser)
?>
Create a text object with custom class 'username' , enter a random text to position the element and add it to your visu.

Add this to custom css:
Code:
.username {
   display: none;
}

Enable password for user folder if you add the .lp file to the user folder (otherwise it shows 'anonymous') and put this into your custom javaScript:
Code:
$(function(){
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
  if (xhttp.readyState == 4 && xhttp.status == 200) {
     var res = xhttp.responseText;
     if (typeof(res) !== "undefined" && res !== null){
        var UpperCaseRes = res.charAt(0).toUpperCase() + res.slice(1);
       $(".username").html(UpperCaseRes);
       $(".username").css("display","initial");
     }
   }
  };
  xhttp.open("GET", "/user/user.lp", true);
  xhttp.send();
});
BR,

Erwin


RE: Username in visu - Thomas - 17.10.2017

Thank you.
LM is a great device but sometimes some simply looking requests have solutions like if you're scratching left ear by right hand behind your head.


RE: Username in visu - Thomas - 17.10.2017

1. The file has to be stored under /www/user/
2. NEVER create any object with just space instead of a text. I spent last 30 minutes by trying to hit this object by mouse with no success. The workaround is to find this object through object inspector and change the missing text.Then you can select the object.


RE: Username in visu - Erwin van der Zwart - 17.10.2017

Hi,

1) Should also be possible from apps/data/yourappfolder
2) Yes, not tested, i position the element with a text and after that i changed text to space because it looked cleaner, never tried to fetch it again .. Sorry (:

Maybe it's better to do it like this so you don't see initial text:

Add this to custom css
Code:
.username {
   display: none;
}

and add this to the custom javaScript:
Code:
$(function(){
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
     if (xhttp.readyState == 4 && xhttp.status == 200) {
        var res = xhttp.responseText;
        if (typeof(res) !== "undefined" && res !== null){
           var uppercaseRes = res.charAt(0).toUpperCase() + res.slice(1);
           $(".username").html(uppercaseRes);
           $(".username").css("display","initial");
        }
     }
  };
  xhttp.open("GET", "/user/user.lp", true);
  xhttp.send();
});
BR,

Erwin


RE: Username in visu - JohnTH - 05.02.2020

Hi, 

I can't get this working.. I saved the user.lp file in /user/user.lp with ftp-user "apps".  Is this correct?
How can I 'Enable password for user folder' ? 

The text object in visualization gets blank when logging in now.
I have saved the custom javascript and css.

Thanks in advance,
John


RE: Username in visu - admin - 05.02.2020

"Enable password for user folder" is set in User access settings (User access tab).


RE: Username in visu - JohnTH - 11.02.2020

Ok, password for user folder was already set in user access tab.
 
When I connect with ftp user 'apps' I uploads the user.lp file to user folder, but this doesn't work.
Thomas says it has to be in placed in /www/user, how can I access this folder?

   


RE: Username in visu - admin - 11.02.2020

FTP user folder points to /www/user/ internally. Can you access http://IP/user/user.lp from your browser?


RE: Username in visu - JohnTH - 11.02.2020

Thanks, I uploaded the user.lp file to / with ftp as user and then change the premissions to this file to 777.
With my browser pointed to this location it shows error:

Error in /www/user/user.lp at line 2: attempt to call global '    require' (a nil value)


user.lp file content:
<?
    require('apps')

    clientuser = request.username or 'anonymous'

    print(clientuser)
?>



-John


RE: Username in visu - admin - 11.02.2020

Remove all spaces before require and all other lines in user.lp


RE: Username in visu - JohnTH - 11.02.2020

Perfect!..  Rolleyes

Thanks, everything works now.

-John