]> projects.mako.cc - selectricity/commitdiff
Added Plugin for dynamically adjusting session options (so they will never
author<jlsharps@mit.edu> <>
Fri, 24 Aug 2007 18:59:36 +0000 (14:59 -0400)
committer<jlsharps@mit.edu> <>
Fri, 24 Aug 2007 18:59:36 +0000 (14:59 -0400)
expire). The code for that, along with a change of the session_key, which
changes how the cookies hash stores teh session_id, are both in the environment
file.

app/controllers/application.rb
app/views/quickvote/my_quickvotes.rhtml
config/environment.rb
db/schema.rb
vendor/plugins/dynamic_sessions/init.rb [new file with mode: 0644]
vendor/plugins/dynamic_sessions/lib/dynamic_session_expiry.rb [new file with mode: 0644]

index 9b4803092dfc48e4c3ed6a006204de60ae39323e..23c878feca92f6d252034ffd965f97612bb22dae 100644 (file)
@@ -6,4 +6,5 @@ class ApplicationController < ActionController::Base
   helper :user
   require_dependency "user"
   
+  
 end
index 546cb24259c9faea131b312648c0bff8ece19dd2..4788bb17fc35ef9813bd595007381f44d7eccefa 100644 (file)
@@ -1,3 +1,4 @@
+<% breakpoint %>
 <table class="voterbox">
   <tr>
   <% ["Name", "Start Date", "End Date", "Description"].each do |column| %>
index 571638d14a3fc1a0ccefbce34442f8cbc1fa8fc0..80f19b46ee25983f4511ac36c4142d8daf895857 100644 (file)
@@ -87,6 +87,10 @@ class String
   end
 end
 
+#Change the session store key, so that it will not conflict with other webapps
+ActionController::Base.session_options[:session_key] = 'selectricity_session_id'
+CGI::Session.expire_after 1.year
+
 # action mailer configuration
 ActionMailer::Base.delivery_method = :sendmail
 ActionMailer::Base.default_charset = "utf-8"
index cc61ca37c0b9abdbf9a6e19760d4749bd2ea6f66..761fe47a5a21ec21d0f699b73010416a5be5a62c 100644 (file)
@@ -21,6 +21,7 @@ ActiveRecord::Schema.define() do
     t.column "enddate",         :datetime,                                   :null => false
     t.column "active",          :integer,  :limit => 4,   :default => 0,     :null => false
     t.column "user_id",         :integer
+    t.column "quickuser",       :string
     t.column "election_method", :string,   :limit => 100, :default => "ssd"
     t.column "type",            :string,   :limit => 100, :default => "",    :null => false
   end
diff --git a/vendor/plugins/dynamic_sessions/init.rb b/vendor/plugins/dynamic_sessions/init.rb
new file mode 100644 (file)
index 0000000..bc1da90
--- /dev/null
@@ -0,0 +1 @@
+require 'dynamic_session_expiry'
\ No newline at end of file
diff --git a/vendor/plugins/dynamic_sessions/lib/dynamic_session_expiry.rb b/vendor/plugins/dynamic_sessions/lib/dynamic_session_expiry.rb
new file mode 100644 (file)
index 0000000..8752365
--- /dev/null
@@ -0,0 +1,38 @@
+# Provides the ability to have session cookies for your Rails app calculated
+# relative to the current time.
+#
+# In your environment.rb file (or in the environments/*.rb file of your choice),
+# do something like the following:
+#
+#   CGI::Session.expire_after 1.month
+#
+# Session cookies will then expire one month after the session was created. This
+# differs from the usual session cookie behavior in that the expiration date is
+# not a fixed time, but rather relative to the current time.
+
+class CGI
+  class Session
+    @@session_expiration_offset = 0
+    
+    def self.session_expiration_offset
+      @@session_expiration_offset
+    end
+    
+    def self.session_expiration_offset=(value)
+      @@session_expiration_offset = value
+    end
+
+    def self.expire_after(value)
+      @@session_expiration_offset = value
+    end
+    
+    alias :initialize_without_dynamic_session_expiration :initialize #:nodoc:
+    def initialize(request, option={}) #:nodoc:
+      if @@session_expiration_offset && @@session_expiration_offset > 0
+        option['session_expires'] = Time.now + @@session_expiration_offset
+      end
+      initialize_without_dynamic_session_expiration(request, option)
+    end
+    
+  end
+end
\ No newline at end of file

Benjamin Mako Hill || Want to submit a patch?