From 108e13f9199648108e61f282a56f9ab4e7bc5dc6 Mon Sep 17 00:00:00 2001 From: Date: Fri, 24 Aug 2007 14:59:36 -0400 Subject: [PATCH] Added Plugin for dynamically adjusting session options (so they will never 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 | 1 + app/views/quickvote/my_quickvotes.rhtml | 1 + config/environment.rb | 4 ++ db/schema.rb | 1 + vendor/plugins/dynamic_sessions/init.rb | 1 + .../lib/dynamic_session_expiry.rb | 38 +++++++++++++++++++ 6 files changed, 46 insertions(+) create mode 100644 vendor/plugins/dynamic_sessions/init.rb create mode 100644 vendor/plugins/dynamic_sessions/lib/dynamic_session_expiry.rb diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 9b48030..23c878f 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -6,4 +6,5 @@ class ApplicationController < ActionController::Base helper :user require_dependency "user" + end diff --git a/app/views/quickvote/my_quickvotes.rhtml b/app/views/quickvote/my_quickvotes.rhtml index 546cb24..4788bb1 100644 --- a/app/views/quickvote/my_quickvotes.rhtml +++ b/app/views/quickvote/my_quickvotes.rhtml @@ -1,3 +1,4 @@ +<% breakpoint %> <% ["Name", "Start Date", "End Date", "Description"].each do |column| %> diff --git a/config/environment.rb b/config/environment.rb index 571638d..80f19b4 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -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" diff --git a/db/schema.rb b/db/schema.rb index cc61ca3..761fe47 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 index 0000000..bc1da90 --- /dev/null +++ b/vendor/plugins/dynamic_sessions/init.rb @@ -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 index 0000000..8752365 --- /dev/null +++ b/vendor/plugins/dynamic_sessions/lib/dynamic_session_expiry.rb @@ -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 -- 2.30.2