Forcing a Login from a button when pressed

I have a button that opens a window for technicians and supervisors, at the moment this button is hidden if the user logged in does not have the security rights to use the button and we log out and back in whenever we need open the window.

I want to display the button at all times and when it is clicked a check is made for the access rights. If the user has the rights to access the window then it should open and if not then a user should be able to login in to access the window.

When the window closes then I would like to switch back to the previous / default user so that access to the window is disabled again.

I was hoping to use a script similar to the one in the screen shot above, but instead of an error box I’d like the login box to appear.

Any ideas

Just create a login popup window and open it.

Thanks for the idea, got it working a treat now

Do you have a sample for login popups, is it done entirely from scripting and components or is there one available as template.

Yes. It is done from scripting and components. I am not aware of any cloud templates for a login window but I could be wrong.
Take a look at https://docs.inductiveautomation.com/display/DOC80/system.security.switchUser to get you started.