GetCurrentUser

tvm
2022-07-15
2024-01-23
  • tvm - 2022-07-15

    I'm using the following code to get information on the current logged in user:

    VAR
        CurrentUser:        VisuUserManagement.VUM_User;
    END_VAR
    
    CurrentUser:= VisuUserManagement.g_VisuUserMgmtIntern.GetCurrentUser();
    

    If I call this with no user logged in, I get the screenshot below, as expected. When I log in, I can see the username, etc, as expected. However, when I log out, the username, password, user groups, etc stay as if I'm still logged in. I would expect to see empty strings in the username, and 0's in the groups, just like the initial screenshot. Do I have to reset it somehow?

     

    Last edit: tvm 2022-07-15
  • TimvH

    TimvH - 2022-08-08

    This doesn't work when you have multiple clients, so you must iterate over the clients and then get the required info per client.

    E.g. add this to a program which you call from the VISU_TASK

    VAR
        pClient : POINTER TO VisuElems.VisuElemBase.VisuStructClientData;
        dwTargetVisuGroupID : DWORD;
    END_VAR
    
    VisuElems.VisuElemBase.g_ClientManager.BeginIteration();
    WHILE (pClient := VisuElems.VisuElemBase.g_ClientManager.GetNextClient()) <> 0 DO
        IF pClient^.GlobalData.ClientType = VisuElems.VisuElemBase.Visu_ClientType.TargetVisualization THEN
            dwTargetVisuGroupID := pClient^.GlobalData.CurrentUserGroupID;
        END_IF
    END_WHILE
    

    See for a general other way of using this "Client handling":
    https://faq.codesys.com/display/CDSFAQ/WebVisu%3A+Reading+the+IP+Address+of+the+Client

     
  • pavel-doreng - 2024-01-23

    Hi
    im only have 3 groups \ users - the deafault ones
    admin \ servie \ operator

    i JUST NEED TO KNOW WHO IS CURRENTLY LOGGED IN
    TO Display the user name , thats all
    this code above do not work for me please help
    im sure its very simple

     
  • TimvH

    TimvH - 2024-01-23

    if you just want to show the currently logged in user in the visualization, then just create a field with text %s and as text variable VisuElems.CurrentUserName

     
    πŸ‘
    1

Log in to post a comment.