From f4fda08e865b1672d5bb4284e32cafdce527f014 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Mon, 5 Mar 2012 16:19:08 +0800 Subject: [PATCH] Replace PrototypeR4 by Orbit. Move session into mongoid_store. Reset session when sing_in. --- Gemfile | 3 ++ Gemfile.lock | 32 +++++++++++++++++++ Rakefile | 2 +- app/controllers/admin/sessions_controller.rb | 8 +++++ app/models/session.rb | 12 +++++++ config.ru | 2 +- config/application.rb | 3 +- config/environment.rb | 2 +- config/environments/development.rb | 2 +- config/environments/production.rb | 2 +- config/environments/test.rb | 2 +- .../cookie_verification_secret.rb | 2 +- config/initializers/secret_token.rb | 2 +- config/initializers/session_store.rb | 7 +--- config/routes.rb | 2 +- .../config/initializers/app_config.rb | 4 +-- 16 files changed, 69 insertions(+), 18 deletions(-) create mode 100644 app/controllers/admin/sessions_controller.rb create mode 100644 app/models/session.rb diff --git a/Gemfile b/Gemfile index eb1f5434..cd8c36f9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,8 @@ source 'http://rubygems.org' gem 'rails', '>=3.1.0', '<3.2.0' +gem "brakeman" + gem 'bson_ext' gem 'carrierwave' gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid' @@ -13,6 +15,7 @@ gem 'kaminari', :git => 'git://github.com/amatsuda/kaminari.git' gem 'mini_magick' gem 'mongoid' +gem "mongo_session_store-rails3" gem 'radius' gem 'rake' gem 'ruby-debug19' diff --git a/Gemfile.lock b/Gemfile.lock index 8889b1d5..b1ab1679 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,6 +42,14 @@ GEM arel (2.2.1) bcrypt-ruby (3.0.1) bcrypt-ruby (3.0.1-x86-mingw32) + brakeman (1.5.0) + activesupport + erubis (~> 2.6) + haml (~> 3.0) + i18n + ruby2ruby (~> 1.2) + ruport (~> 1.6) + sass (~> 3.0) bson (1.5.2) bson_ext (1.5.2) bson (= 1.5.2) @@ -59,6 +67,7 @@ GEM coffee-script-source execjs coffee-script-source (1.2.0) + color (1.4.1) columnize (0.3.6) database_cleaner (0.7.1) delorean (1.2.0) @@ -78,7 +87,11 @@ GEM factory_girl_rails (1.6.0) factory_girl (~> 2.5.0) railties (>= 3.0.0) + fastercsv (1.5.4) + haml (3.1.4) hike (1.2.1) + hoe (2.15.0) + rake (~> 0.8) i18n (0.6.0) jquery-rails (1.0.19) railties (~> 3.0) @@ -96,12 +109,18 @@ GEM subexec (~> 0.2.1) mongo (1.5.2) bson (= 1.5.2) + mongo_session_store-rails3 (3.0.5) + actionpack (>= 3.0) + mongo mongoid (2.4.2) activemodel (~> 3.1) mongo (~> 1.3) tzinfo (~> 0.3.22) multi_json (1.0.4) orm_adapter (0.0.6) + pdf-writer (1.1.8) + color (>= 1.4.0) + transaction-simple (~> 1.3) polyglot (0.3.3) rack (1.3.6) rack-cache (1.1) @@ -154,15 +173,24 @@ GEM columnize (>= 0.3.1) linecache19 (>= 0.5.11) ruby-debug-base19 (>= 0.11.19) + ruby2ruby (1.3.1) + ruby_parser (~> 2.0) + sexp_processor (~> 3.0) ruby_core_source (0.1.5) archive-tar-minitar (>= 0.5.2) + ruby_parser (2.3.1) + sexp_processor (~> 3.0) rubyzip (0.9.5) + ruport (1.6.3) + fastercsv + pdf-writer (= 1.1.8) sass (3.1.12) sass-rails (3.1.5) actionpack (~> 3.1.0) railties (~> 3.1.0) sass (~> 3.1.10) tilt (~> 1.3.2) + sexp_processor (3.1.0) shoulda-matchers (1.0.0) simplecov (0.5.4) multi_json (~> 1.0.3) @@ -186,6 +214,8 @@ GEM tilt (1.3.3) tinymce-rails (3.4.8) railties (>= 3.1) + transaction-simple (1.4.0) + hoe (>= 1.1.7) treetop (1.4.10) polyglot polyglot (>= 0.3.1) @@ -210,6 +240,7 @@ PLATFORMS x86-mingw32 DEPENDENCIES + brakeman bson_ext carrierwave carrierwave-mongoid @@ -223,6 +254,7 @@ DEPENDENCIES jquery-rails kaminari! mini_magick + mongo_session_store-rails3 mongoid radius rails (>= 3.1.0, < 3.2.0) diff --git a/Rakefile b/Rakefile index 2036d04c..9a495de7 100644 --- a/Rakefile +++ b/Rakefile @@ -5,4 +5,4 @@ require File.expand_path('../config/application', __FILE__) require 'rake/dsl_definition' require 'rake' -PrototypeR4::Application.load_tasks +Orbit::Application.load_tasks diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb new file mode 100644 index 00000000..00649580 --- /dev/null +++ b/app/controllers/admin/sessions_controller.rb @@ -0,0 +1,8 @@ +class SessionsController < Devise::SessionsController + + def create + super + reset_session + end + +end \ No newline at end of file diff --git a/app/models/session.rb b/app/models/session.rb new file mode 100644 index 00000000..3c6deb54 --- /dev/null +++ b/app/models/session.rb @@ -0,0 +1,12 @@ +class Session + include Mongoid::Document + include Mongoid::Timestamps + + def self.sweep(time = 1.hour) + if time.is_a?(String) + time = time.split.inject { |count, unit| count.to_i.send(unit) } + end + + delete_all "updated_at < '#{time.ago.to_s(:db)}' OR created_at < '#{2.days.ago.to_s(:db)}'" + end +end \ No newline at end of file diff --git a/config.ru b/config.ru index 20d6bd1f..6a593e4a 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) -run PrototypeR4::Application +run Orbit::Application diff --git a/config/application.rb b/config/application.rb index 50b9f4a7..d1243133 100644 --- a/config/application.rb +++ b/config/application.rb @@ -13,12 +13,13 @@ require 'sprockets/railtie' # or test environments. Bundler.require *Rails.groups(:assets) if defined?(Bundler) -module PrototypeR4 +module Orbit class Application < Rails::Application # Add directories for plugins config.paths["vendor/plugins"] += %W(#{config.root}/vendor/built_in_modules) config.paths["vendor/plugins"] += %W(#{config.root}/vendor/downloaded_modules) + config.paths.app.views << "app/views/devise" # Settings in config/environments/* take precedence over those specified here. diff --git a/config/environment.rb b/config/environment.rb index efd38a40..3538bc87 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -4,4 +4,4 @@ require 'yaml' YAML::ENGINE.yamler = 'syck' # Initialize the rails application -PrototypeR4::Application.initialize! +Orbit::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index c2b4c930..1dbff032 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,4 +1,4 @@ -PrototypeR4::Application.configure do +Orbit::Application.configure do # Settings specified here will take precedence over those in config/application.rb # In the development environment your application's code is reloaded on diff --git a/config/environments/production.rb b/config/environments/production.rb index f52ead13..001ff2c6 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,4 +1,4 @@ -PrototypeR4::Application.configure do +Orbit::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The production environment is meant for finished, "live" apps. diff --git a/config/environments/test.rb b/config/environments/test.rb index 6d22bb12..e55cc24b 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,4 +1,4 @@ -PrototypeR4::Application.configure do +Orbit::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The test environment is used exclusively to run your application's diff --git a/config/initializers/cookie_verification_secret.rb b/config/initializers/cookie_verification_secret.rb index 5a8601a7..694e666d 100644 --- a/config/initializers/cookie_verification_secret.rb +++ b/config/initializers/cookie_verification_secret.rb @@ -4,4 +4,4 @@ # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -PrototypeR4::Application.config.secret_token = 'cbf6409102b30cb9f4da455ee08c3a7e9d8b2a3d32a0e5b59a354dad03f469d363a8127ef4b7bc3b1afa632d7cf947a1e59e09022d2d4cd8df1f4fa521d7ec07' +Orbit::Application.config.secret_token = 'cbf6409102b30cb9f4da455ee08c3a7e9d8b2a3d32a0e5b59a354dad03f469d363a8127ef4b7bc3b1afa632d7cf947a1e59e09022d2d4cd8df1f4fa521d7ec07' diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index 67abf723..ae9a444a 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -4,4 +4,4 @@ # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -PrototypeR4::Application.config.secret_token = 'b8d78ecaf3086ebfc1ba42e912acba60d85cf3d789d933e117770e1a045a12911f121ff012a234982abb446c8b8c768052eea4bf8b2d5d336be821e2c25d8cdb' +Orbit::Application.config.secret_token = 'b8d78ecaf3086ebfc1ba42e912acba60d85cf3d789d933e117770e1a045a12911f121ff012a234982abb446c8b8c768052eea4bf8b2d5d336be821e2c25d8cdb' diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index e6387adb..b1a4a2c1 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,8 +1,3 @@ # Be sure to restart your server when you modify this file. -PrototypeR4::Application.config.session_store :cookie_store, :key => '_prototype_R4_session' - -# Use the database for sessions instead of the cookie-based default, -# which shouldn't be used to store highly confidential information -# (create the session table with "rails generate session_migration") -# PrototypeR4::Application.config.session_store :active_record_store +Orbit::Application.config.session_store :mongoid_store diff --git a/config/routes.rb b/config/routes.rb index cd3921f0..112d96e1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,4 @@ -PrototypeR4::Application.routes.draw do +Orbit::Application.routes.draw do devise_for :users diff --git a/vendor/built_in_modules/new_blog/config/initializers/app_config.rb b/vendor/built_in_modules/new_blog/config/initializers/app_config.rb index c098b837..0e9f56e7 100644 --- a/vendor/built_in_modules/new_blog/config/initializers/app_config.rb +++ b/vendor/built_in_modules/new_blog/config/initializers/app_config.rb @@ -3,7 +3,7 @@ # # Add a load path for this specific Engine # # config.autoload_paths << File.expand_path("../lib/some/path", __FILE__) # put "ABC" -# PrototypeR4::Application::Orbit_Apps << "NewBlog" +# Orbit::Application::Orbit_Apps << "NewBlog" # # # initializer "my_engine.add_middleware" do |app| # # app.middleware.use MyEngine::Middleware @@ -15,4 +15,4 @@ module NewBlog VERSION = "0.0.1" MOUDLEAPP_TITLE = "NewBlog" end -# PrototypeR4::Application::Orbit_Apps << "NewBlog" \ No newline at end of file +# Orbit::Application::Orbit_Apps << "NewBlog" \ No newline at end of file