We have a reception desk with 2 computers and multiple people who use them and nobody was logging out of their mews account, so the first person who logged into mews that morning had every action on their name. What I did is create a code that loges out every x minutes and adds a keyboard shortcut Ctrl + L
I thought I could be handy for more smaller hotels who have multiple employees sharing one pc.
// Set the desired logout time in minutes
const LogoutMinutes = 15;
// Calculate the logout time in milliseconds (1 minute = 60000 milliseconds)
const LogoutTime = LogoutMinutes * 60000;
// Initialize the timer variable
let timer = null;
// Add an event listener for 'keydown' events
document.addEventListener('keydown', e => {
// Reset the timer on any key press
resetTimer();
// If 'Control' key is held down and the 'l' key is pressed, log out
if (e.ctrlKey && e.key === 'l') {
// Prevent the default behavior of the 'l' key
e.preventDefault();
// Call the logout function
logout();
}
}, false);
// Add an event listener for 'mousemove' events
document.addEventListener('mousemove', () => {
// Reset the timer on any mouse movement
resetTimer();
}, false);
// Define the logout function
function logout() {
// Click the user avatar
const avatar = document.querySelector('[data-test-id="user-menu-avatar"]');
avatar.click();
// Click the "Lock Account" option after a short delay
setTimeout(() => document.querySelector('[value="Lock Account"]').click(), 100);
}
// Define the resetTimer function
function resetTimer(newT = LogoutTime) {
// Clear the existing timer
clearTimeout(timer);
// Set a new timer with the specified timeout
timer = setTimeout(logout, newT);
}
// Call resetTimer to start the initial timer
resetTimer();
This is such an awesome solution, Dirkjan! Thank you so much for sharing it with the community.
Would you mind terribly if our Mews Support Team documented your recommendation in our public help center? We would, of course, give you all the credit for your hard work!
Hey @Dirkjan Thanks for the input. We’re always striving to make Mews the best it can be and we have more exciting features in the pipeline. I can see you’ve voted on these improvements that you’ve mentioned in our Feature Request site so stay tuned for updates from the product team.
We’re working on introducing more community-led product discussions too so when we plan to have the next one, I’ll be sure to let you know.
Hi there! Great script and great idea, ideed!
There might have been an update in the meantime, so the script above does not work for me any more, because the DOM identifier of the lock session element has changed.
However, it’s easy to amend, just
replace
It also loads (@require …. ) the external module HackTimer (https://github.com/turuslan/HackTimer ), which should allow the timer to run also in backgrounded browser tabs. I have not verified that third party module - so use at your own risk and evaluation - but it looks to be rather simple and harmless to me.
For all thos using Chrome - look at the following post by a mews employee (@CharlieDelamare) who made a custom chrom extension that solves that very elegantly.
@CharlieDelamare @rui.oliveira could be a nice feature to also have in the (security) privileges; eg that an admin can ‘force’ this on a property level!
@CharlieDelamare @rui.oliveira could be a nice feature to also have in the (security) privileges; eg that an admin can ‘force’ this on a property level!