Question

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

Was it helpful?

Solution

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

OTHER TIPS

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top