Show
Ignore:
Timestamp:
09/26/2007 03:52:10 (14 months ago)
Author:
zimbatm
Message:

Working on Sessions and database :

  • FIX: Session table was always created
  • FIX: Sessions weren't stored correctly because of the custom
    non-autoincrement id. Using SQL injection to bypass the forced "id" :-]
    (aka. where opinionated software is not always good)
  • ENHANCEMENT: Added index for sessions's hashid for faster lookup
  • FIX: 'sqlite3_api' was loaded after the connection.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/camping/session.rb

    r205 r225  
    1212# For a basic tutorial, see the *Getting Started* section of the Camping::Session module. 
    1313require 'camping' 
     14require 'camping/db' 
    1415 
    1516module Camping::Models 
     
    1819class Session < Base 
    1920    serialize :ivars 
     21    # SQL injection to bypass id field checks 
     22    set_primary_key '"="" OR "' 
     23 
    2024    def []=(k, v) # :nodoc: 
    2125        self.ivars[k] = v 
     
    3943    # If none is found, generates a new session. 
    4044    def self.persist cookies 
     45        session = nil 
    4146        if cookies.camping_sid 
    4247            session = Camping::Models::Session.find_by_hashid cookies.camping_sid 
     
    6469            ActiveRecord::Schema.define do 
    6570                create_table :sessions, :force => true, :id => false do |t| 
    66                     t.column :hashid,      :string,  :limit => 32 
     71                    t.column :hashid,      :string,  :limit => 32, :null => false 
    6772                    t.column :created_at,  :datetime 
    6873                    t.column :ivars,       :text 
    6974                end 
     75                add_index :sessions, [:hashid], :unique => true 
    7076            end 
    7177            reset_column_information 
     
    109115        @state = (session[app] ||= Camping::H[]) 
    110116        hash_before = Marshal.dump(@state).hash 
    111         s = super(*a) 
     117        return super(*a) 
     118    ensure 
    112119        if session 
    113120            hash_after = Marshal.dump(@state).hash 
     
    117124            end 
    118125        end 
    119         s 
    120126    end 
    121127end