0

Is it possible to show "Already Logged In" message if that user is logged on one of the machine. This thing is possible using database. But i had implemented sessions for login and logout,i think it isn't possible with sessions to show "Already Logged In".

Please suggest best way for this.

Sandip Karanjekar
  • 850
  • 1
  • 6
  • 23

3 Answers3

0

If they go to another computer? If you are using session[:something] - it is stored in the browser. For anything to be stored across a different browser, you have to use a database for state.

andrewpthorp
  • 4,998
  • 8
  • 35
  • 56
0

I think it is possible, but that being said, I don't like it. I take it you are concerned because you can't easily identify a user from the session data?

Make sure the User model is updated every time a user accesses the application by using a before_filter in the application controller.

During the login process, you can query "logged in" users by specifying a time limit that is the same as the session clean up time limit.

You can do something like this :

User.where("email = ? and updated_at >= ?",login_email,20.minutes.ago)
cgr
  • 1,093
  • 1
  • 8
  • 14
0

If you want to avoid concurrent logins for the same username. The best implementation can be achieved by adding a column to the users table that stores the ip address of the logged in user.

Otherwise you can change the session store mechanism to use either of:

  • ActiveRecordStore
  • FileStore
  • DRbStore
  • MemoryStore

in addition to the default CookieStore.

Reza
  • 1,478
  • 1
  • 15
  • 25