When ever a user loggedIn to my application , I am saving the loginStatus as"LoggedIn" in Database for that user .(So multiple login cant take place from different computers).
It works fine for me , But in 1 scenario i am facing issue .
If a user just leave his pc and go away , Now he's trying to login from an other pc . But his loginStatus in db is still "loggedIn".So he is unable to login from other pc until and unless he go to the other pc(where he was previously loggedIn) and log himself out.
Anyway i can handle this , Ideally if there is a way of Loggingout User Automatically from previous pc/browser when ever he tries to attempt from some other location.
I call this method when user clicks on LOGOUT link, which makes session invalid , and also make a call to db.. What i want is to make a call to this method When there is an inactivity for lets say 2 minutes,Or user simply close his browser (Without LogginOut)
public String logOut() throws Exception {
System.out.println("inside server");
User user = (User) session.getAttribute("user");
logoutFromDb(user);// call to db
session=getThreadLocalRequest().getSession(true);
session.invalidate();
System.out.println("invalidated");
Trying this
DateTime lastAccessedTime = new DateTime(session.getLastAccessedTime());
DateTime currentTime = new DateTime();
Minutes diff = Minutes.minutesBetween(currentTime, lastAccessedTime);
if (diff.getMinutes()>1){
logOut();
But lastAccessedTime is having the time when the code came to this line itself last time
this line:
DateTime lastAccessedTime = new DateTime(session.getLastAccessedTime());
So it not giving the actual time when User did some thing , Instead it give me the time when this line was called..