openstreetmap-website/vendor/plugins/session-persistence
Tom Hughes 26b217c0ad Work round session expiry bug in rails 2.3.11
Rails uses :expire_after in the session options to specify when a
sesssion should expire, but when Rack sets the cookie it expects to
see :expires in the cookie options but Rails 2.3.11 fails to do the
conversion so doesn't set the cookie expiry.

To work around this, we set both options in the session options...
2011-06-02 10:23:22 +01:00
..
lib Work round session expiry bug in rails 2.3.11 2011-06-02 10:23:22 +01:00
test Add a plugin to handle session persistence. This is based on the 2010-02-25 16:39:51 +00:00
init.rb Add a plugin to handle session persistence. This is based on the 2010-02-25 16:39:51 +00:00
MIT_LICENSE Add a plugin to handle session persistence. This is based on the 2010-02-25 16:39:51 +00:00
README.rdoc Add a plugin to handle session persistence. This is based on the 2010-02-25 16:39:51 +00:00

= Session Persistence

Rails 3 plugin that lets you set how long you want your session to be persisted/remembered.

 session_expires_after 2.weeks
 session_expires_automatically # also aliased to expire_session
   
The timespan will reset on every request. If you set it to 2 weeks, and the user returns after 1 week, the session will be refreshed and last 2 weeks again. If the user returns after 3 weeks, the session will be reset.

A call to session_expires_automatically will return to a normal automatical expiry cookie, that will expire when the browser is closed.

Note: I haven't tested the plugin with memcache session storage, but it should work there as well.

= Usage
   
Here's an example sessions controller in a Rails 3 application.

 class SessionsController < ApplicationController
  def create
    session_expires_after 2.weeks if params[:remember_me]
    
    # ..normal auth goes here..
    # for example
    user = User.authenticate(params[:username], params[:password])
    if user
      session[:user] = user.id
    else
      # ..
    end
  end
  
  def destroy
    session_expires_automatically
    
    # ..unauthorize here..
    # for example
    session[:user] = nil
    redirect_to root_path
  end
 end