My application uses Rails 3.0.4 and Devise 1.1.7.
I am looking for a way to prevent users from using accounts, as the application is a subscription-based service. I searched for over a week, and I still don't know how to implement the solution. I hope someone fulfills the decision and can point me in the right direction.
Solution (Thank you all for your answers and understanding!)
In controller.rb application
before_filter :check_concurrent_session def check_concurrent_session if is_already_logged_in? sign_out_and_redirect(current_user) end end def is_already_logged_in? current_user && !(session[:token] == current_user.login_token) end
In session_controller, which overrides the Devise Sessions controller:
skip_before_filter :check_concurrent_session def create super set_login_token end private def set_login_token token = Devise.friendly_token session[:token] = token current_user.login_token = token current_user.save end
In migration AddLoginTokenToUsers
def self.up change_table "users" do |t| t.string "login_token" end end def self.down change_table "users" do |t| t.remove "login_token" end end
ruby-on-rails ruby-on-rails-3 session devise
John Aug 15 '11 at 18:23 2011-08-15 18:23
source share