For anyone searching this, I came up with my own solution that seems to work for all scenarios I have tried so far. Not sure if it is the most elegant or streamlined way, but it works well.
Create a client startup script (this runs anytime a new user logs in)
current_id = system.util.getClientId()
current_user = system.security.getUsername()
sessions = system.util.getSessionInfo()
match = False
for row in sessions:
if row["username"] == current_user and row["clientId"] != current_id and row["isDesigner"] == False:
match = True
break
if match:
system.util.sendMessage(project = project_name,
messageHandler='AutoLogout',
payload = {'message' : current_id},
scope = 'C',
user = current_user)
system.gui.messageBox ("User's other open sessions have been logged out")
if not match: (insert your other code if needed)
This will check the sessions. If the same username as the current user is in the list with a different client id that the one you are logging in with (and is not a designer session) then send a message to all other client sessions with the same username as the active user.
Then make a simple receive message script
system.gui.messageBox ("User logged into another session. This session will be logged out")
system.security.logout()
I thought I would have to do more code in the receive script to prevent the session sending the message from being logged out as well but it doesnt seem to work this way. I guess the session ‘sending’ the message also doesnt ‘receive’ that same message.
Try something like this, idk if its correct tho.
The current_id might be something else, i dont seem to get the same thing in the desinger, but it might work on client
sessions = system.perspective.getSessionInfo()
current_id = self.session.props.id
current_user = self.session.props.auth.user.userName
for row in sessions:
if row["username"] == current_user and row["id"] != current_id and row["sessionScope"] != "designer":
for page in row['pageIds']:
system.perspective.logout(row["id"], page)
the “message box” will have to be a popup or somehting if you want that
I’m not sure whether the location I code is correct or not which I write my script in the session events startup. Can you help me to confirm whether I’m correct or not. Thanks in advance.
Did you try to do something like this before by the way thanks for your help.