Guest User

Untitled

a guest
Jun 6th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. Devise - Invalidate user session if the same user logs in from a different browser/machine
  2. class AddSignInTokenToUsers < ActiveRecord::Migration
  3. def change
  4. add_column :users, :current_sign_in_token, :string
  5. end
  6. end
  7.  
  8. class ApplicationController < ActionController::Base
  9. before_filter :invalidate_simultaneous_user_session, :unless => Proc.new {|c| c.controller_name == 'sessions' and c.action_name = 'create' }
  10.  
  11. def invalidate_simultaneous_user_session
  12. sign_out_and_redirect(current_user) if current_user && session[:sign_in_token] != current_user.current_sign_in_token
  13. end
  14.  
  15. def sign_in(resource_or_scope, *args)
  16. super
  17. token = Devise.friendly_token
  18. current_user.update_attribute :current_sign_in_token, token
  19. session[:sign_in_token] = token
  20. end
  21. end
Advertisement
Add Comment
Please, Sign In to add comment