openstreetmap-website/vendor/plugins/session-persistence
2011-11-14 09:42:44 +00:00
..
lib Go back to the rails 3 based upstream version of session-persistence 2011-11-14 09:42:44 +00: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