Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
666 views
in Plugins by
I'd like to automatically log a user out if they haven't done anything for x minutes so that they have to log in again. I'm pretty sure this feature isn't available in Q2A core so I'll probably need to write a plugin. Does anyone have any ideas on where to run code. Code needs to update a custom table and check inactivity period so it needs to run every time the user gets a page back. I'm OK with the coding and functionality - Just not sure which function is best to overide?. Any ideas?
Q2A version: 1.6.3
by
I need to logout the user after 1 day do you know how to do so?

1 Answer

+1 vote
by
selected by
 
Best answer

define a layer and an event module. when ever an event was called in event module add a new item for event's caller to ^userneta tables(functions and table already exists) with "time of event" as value.

in layer's DocType function get logged in user's meta info for user's last event's date. if (current time > event time + ideal inactivity time) then log user out and redirect to current page or anywhere you like.

by
Thanks for the advice. I managed to do it a slightly different way.
I've written a plugin with a process module which uses the init_page() function. All the processing is done there in that function. Not sure whether that's an efficient place to do the check just seemed logical to do it at the start of a request for a web page.
by
yes, that should be faster. I usually use layers because when it's called forms are already processed and Q2A functions that might be needed are already included.
...