Hi,
Define a method in your service that returns the last time the user interacted with the server (in the code below it is getLastRequest()).
In your main screen define these variables:
protected static final long DEFAULT_TIMEOUT = 20 * 60 * 1000l; // 20 minutes
protected static final long ABSOLUTE_TIMEOUT = 12 * 60 * 60 * 1000l; // 12 hours
private long TIMEOUT = DEFAULT_TIMEOUT;
After displaying main screen, run something like this:
final long loginTime = System.currentTimeMillis();
Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() {
@Override
public boolean execute() {
long dif = System.currentTimeMillis() - MYSERVICE.getLastRequest();
long loginDif = System.currentTimeMillis() - loginTime;
if (dif > TIMEOUT || loginDif > ABSOLUTE_TIMEOUT) {
MYSERVICE.getService().logout(user.getId(), new AsyncCallback<String[]>() {
@Override
public void onFailure(Throwable caught) {
// TODO handle error
}
@Override
public void onSuccess(String[] result) {
MYSERVICE.getController().handleEvent(new AppEvent(AppEvents.Logout));
if (!result[0].equals(Responses.SUCCESS)) {
// TODO display login screen
}
}
});
return false;
}
return true; //as long as it returns true the execute is repeated after XX milliseconds
}
}, 10000);
Hope this helps,
Rodolfo M. Raya
On Thu, Dec 28, 2017 at 1:34 PM Devaraj Rathinasamy <rdevaraj.it@gmail.com> wrote:
--We need to auto log out the user after a max user inactivity time (say 5 mins) in our GWT MVP with history management application. Appreciate any inputs on how to proceed implementation for this.We have session timeout at service level. so if any interaction happens with the server, server session will be validated and inactivated if expired. But in above case, user should be auto logged out after max inactivity time without any user interaction.
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment