This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Username in visu
#1
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
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply
#2
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
Reply
#3
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.
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply
#4
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.
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply
#5
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
Reply
#6
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
Reply
#7
"Enable password for user folder" is set in User access settings (User access tab).
Reply
#8
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?

   
Reply
#9
FTP user folder points to /www/user/ internally. Can you access http://IP/user/user.lp from your browser?
Reply
#10
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
Reply
#11
Remove all spaces before require and all other lines in user.lp
Reply
#12
Perfect!..  Rolleyes

Thanks, everything works now.

-John
Reply


Forum Jump: