I am using a slightly different session modul with a small and dirty 
Camping hack for implemeting the Remember me function (used on 
http://dekk.hu/).


@headers["Set-Cookie"[EMAIL 
PROTECTED]|k,v|"#{k}=#{k=~/_sid$/?v:C.escape(v)};#{"max-age=0;"if 
!v}path=#{self/'/'}"if [EMAIL PROTECTED];


Camping does not escape a cookie variable if its name ends with "_sid", 
so i can add after the session_id a max_age value as described below in 
remember_me and forget_me functions. (The "application" function gets 
only the name of the the app.)


module Camping

  module WigwamSession
    include Camping::Helpers

    def sessioncookie
      "#{application.to_s.downcase}_sid"
    end

    def remember_me
      @cookies[sessioncookie] = @session_id + ';max-age=31536000'
    end

    def forget_me
      @cookies[sessioncookie] &&= @session_id + ';max-age=0'
    end

    def service(*a)
      session = Camping::Models::WigwamSession.find_by_sessionid 
@cookies[sessioncookie] if @cookies[sessioncookie]
      if session
        @session_id = session.sessionid
        @state = session.variables
      else
        @session_id = [*0..31].map { ([*'A'..'Z'] + [*'a'..'z'] + 
[*'0'..'1'])[rand(62)] }.join
        @state = Camping::H[]
      end
      @cookies[sessioncookie] = @session_id
      state = @state.dup
      s = super(*a)
      if @state.empty?
        session.destroy if session
      elsif @state != state
        unless session
          Camping::Models::WigwamSession.create :sessionid => 
@session_id, :variables => @state
        else
          session.variables = @state
          session.save
        end
      end
      s
    end
  end
end


The possibility of adding "max-age" value for a cookie in the new 
version of Camping without hack the original source would be really great...

Greetings, Bence

-- 
Nagy Bence
-> Tipográl | www.tipogral.hu
-> Tipokert | www.tipokert.hu
-> Dekk | www.dekk.hu
-> Magyar Grafika | www.mgonline.hu
-> Hírkapu | www.hirkapu.hu

_______________________________________________
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Reply via email to