Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Login/logout Javascript event

Login/logout Javascript event

FadEr
New Poster
Hello,

is there a javascript event for login and logout in webiq? I would like to change the value of an item with javascript when a user logs in and when he logs out.

Is this possible?

Thank you
1 REPLY 1

webiq-sk
Frequent Contributor

There is no specific event, because a logout simply reloads the page resulting in the user seeing the login form again. You cannot execute any custom code if not logged in, because you don't have any connection to the server yet as the websocket connection has to be authenticated before being able to do that.

However, to "catch" a login simply add a LocalScript somewhere in your HMI that is shown by default - that will be executed everytime that area is shown - as is true for all LocalScripts.

You could however simply add the UI action "write item" followed by "logout (final)" on a logout button - this will write the item and logout the user. Please note that it says "final", because you cannot add any more UI actions after that one, because as described before the page is simply reloaded.

Please keep in mind that you can have potentially unlimited numbers of users logged in at the same time in your HMI (depending on the "clients" part of your license, by default two) that can access completely different parts of the HMI. As such your requirement only works if there will ever only be a single user at all logged in to your HMI at the same time. Otherwise, the latest user will always overwrite the previous one.

Please also note that if the network connection breaks for whatever reason you will not be able to catch the implicit logout - it will still appear as "loggedin" in your PLC then.  You could however simply create a LocalScript that writes the username every few seconds so you can detect in the HMI if it's not written anymore which would mean that there is no active user anymore.

Still, you have to handle multiple users logged in at once.

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist