Preventing multiple account logins on the same device/machine in Rails 3 with Devise
Half or more of our users fall within a specific demographic that consists of expats. Quite a few of them are couples that share the same machine but have separate accounts. For the sake of data integrity I want to close an existing session on a machine if another log in is attempted with the second user's account. Anyone know how to d开发者_高级运维o this?
Thanks!
UPDATE: Not quite sure how i could use this info yet. Not sure of the syntax either. What object? Can you access it if you don't know whether it exists?
(Object) resource
Gets the actual resource stored in the instance variable
(Object) signed_in_resource
Returns a signed in resource from session (if one exists)
UPDATE2: Getting closer... i think. Perhaps the session cookie is the key. Wondering how i delete it at the end of a session. If one exists, if i delete it, then that kills the existing session and then the login can then begin the new one. Work on this when i get back from my lunch appt.
The answer was so easy. Deleting the cookie terminates the session.
if cookies[:_Applicationname_session]
cookies.delete(:_Applicationname_session)
end
'Applicationname' is whatever the application name is. It is found, among other places, in your application.rb file. e.g.:
module Applicationname
class Application < Rails::Application
IMPORTANT: Don't forget the underscore that preceeds Applicationname.
精彩评论