Reputation: 699
I know i can do dynamic session timeout (per user) with devise like described here
This worked fine before but now i'm using rails session store and it doesn't work anymore.
I googled quite a long time but didn't find an answer, does anyone know how to do this?
Thanks
Upvotes: 1
Views: 2070
Reputation: 1865
The most simplest approach for session timeout using devise would be to use Devise 'timeoutable' module. Following 2 lines will serve the session timeout functionality, Only if u are using devise in your Rails application.
Step 1: In your User.rb Model declare this
devise: timeoutable
Step 2:
in app/config/initializers/devise.rb add following line, default set by Devise is 30 minutes.
config.timeout_in = 15.minutes
Hope this works for you!
Thanks!
Upvotes: 1
Reputation: 699
I've done it now with some before_filters:
class ApplicationController < ActionController::Base
before_filter :update_session, :check_if_session_is_valid
...
def check_if_session_is_valid
session_timeout = current_user.try(:session_timeout) || 1800
if session[:timestamp] <= session_timeout.seconds.ago.to_i
session[:user_id] = nil
end
end
def update_session
session[:timestamp] = Time.now.to_i
end
And in the controller which is used by the poller i added this (the session shouldn't get updated by the poller):
skip_before_filter :update_session, :only => :get_new
Upvotes: 1