From 18968a05b1f8ce2949050ac9ab3e23f53c929a10 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Mon, 24 Mar 2014 12:45:04 +0100 Subject: [PATCH] * Update devise to latest version * use letter_opener for mails in development * bring back the flash * fix redirect loop for logging in * move all mailer/devise settings to config/config.yml --- Gemfile | 5 +++-- Gemfile.lock | 23 +++++++++++++++++------ app/assets/stylesheets/osem.css | 2 +- app/controllers/application_controller.rb | 8 +++++++- app/models/email_settings.rb | 4 ++-- config/config.yml.example | 5 ++++- config/environment.rb | 9 +++++++++ config/environments/development.rb | 5 ++++- config/environments/production.rb | 3 +++ config/initializers/devise.rb | 4 +++- config/initializers/osem.rb | 1 - 11 files changed, 53 insertions(+), 16 deletions(-) delete mode 100644 config/initializers/osem.rb diff --git a/Gemfile b/Gemfile index 7ac7554e..89ac4324 100644 --- a/Gemfile +++ b/Gemfile @@ -20,11 +20,12 @@ group :development, :test do gem 'pry' gem 'sqlite3' gem 'thin' - gem 'rspec-rails', '2.11.0' + gem 'letter_opener' end group :production do gem 'mysql2' + gem 'rspec-rails', '2.11.0' end group :test do @@ -36,7 +37,7 @@ gem 'paperclip', '~> 3.0' gem 'jquery-rails' gem 'jquery-ui-rails' gem 'jquery-fileupload-rails' -gem 'devise', '~> 2.2' +gem 'devise' gem 'cancan' gem "haml" gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index 403a2339..ece99731 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -34,7 +34,9 @@ GEM activerecord (>= 3.0) activesupport (>= 3.0) awesome_nested_set (>= 2.0) + addressable (2.3.5) arel (3.0.3) + atomic (1.1.16) awesome_nested_set (2.1.6) activerecord (>= 3.0.0) axlsx (2.0.1) @@ -44,6 +46,7 @@ GEM axlsx_rails (0.1.5) axlsx rails (>= 3.1) + bcrypt (3.1.7) bcrypt-ruby (3.0.1) bootstrap-sass (3.1.1.0) sass (~> 3.2) @@ -67,11 +70,12 @@ GEM d3_rails (3.4.3) railties (>= 3.1.0) daemons (1.1.9) - devise (2.2.8) - bcrypt-ruby (~> 3.0) + devise (3.2.4) + bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (~> 3.1) - warden (~> 1.2.1) + railties (>= 3.2.6, < 5) + thread_safe (~> 0.1) + warden (~> 1.2.3) diff-lcs (1.1.3) erubis (2.7.0) eventmachine (1.0.3) @@ -97,6 +101,10 @@ GEM jquery-ui-rails (4.1.2) railties (>= 3.1.0) json (1.8.1) + launchy (2.4.2) + addressable (~> 2.3) + letter_opener (1.2.0) + launchy (~> 2.2) libv8 (3.16.14.3) mail (2.5.4) mime-types (~> 1.16) @@ -104,7 +112,7 @@ GEM method_source (0.8.2) mime-types (1.25.1) mini_portile (0.5.2) - multi_json (1.9.0) + multi_json (1.9.2) mysql2 (0.3.15) nokogiri (1.6.1) mini_portile (~> 0.5.0) @@ -194,6 +202,8 @@ GEM eventmachine (>= 1.0.0) rack (>= 1.0.0) thor (0.18.1) + thread_safe (0.3.1) + atomic (>= 1.1.7, < 2) tilt (1.4.1) transitions (0.1.12) treetop (1.4.15) @@ -224,13 +234,14 @@ DEPENDENCIES capybara (= 1.1.2) cocoon d3_rails - devise (~> 2.2) + devise formtastic-bootstrap gravtastic haml jquery-fileupload-rails jquery-rails jquery-ui-rails + letter_opener mysql2 paper_trail paperclip (~> 3.0) diff --git a/app/assets/stylesheets/osem.css b/app/assets/stylesheets/osem.css index 99c7fc36..8f264dca 100644 --- a/app/assets/stylesheets/osem.css +++ b/app/assets/stylesheets/osem.css @@ -7,7 +7,7 @@ body { margin-bottom: 60px; } -body > #content { +body > #messages { padding: 60px 15px 0; } diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 57495640..8eb1d349 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,7 +9,13 @@ class ApplicationController < ActionController::Base end def after_sign_in_path_for(resource) - session[:return_to] + if not session[:return_to].start_with?('/accounts') + logger.debug "Returning to #{session[:return_to]}" + session[:return_to] + else + logger.debug "Not returning to #{session[:return_to]} because it would loop" + super + end end def get_conferences diff --git a/app/models/email_settings.rb b/app/models/email_settings.rb index 7893f157..82d57fd6 100644 --- a/app/models/email_settings.rb +++ b/app/models/email_settings.rb @@ -8,12 +8,12 @@ class EmailSettings < ActiveRecord::Base "email" => person.email, "name" => person.public_name, "conference" => conference.title, - "registrationlink" => Rails.application.routes.url_helpers.register_conference_url(conference.short_title, :host => OSEM_CONFIG["url_for_emails"]) + "registrationlink" => Rails.application.routes.url_helpers.register_conference_url(conference.short_title, :host => CONFIG["url_for_emails"]) } if !event.nil? h["eventtitle"] = event.title - h["proposalslink"] = Rails.application.routes.url_helpers.conference_proposal_url(conference.short_title, event, :host => OSEM_CONFIG["url_for_emails"]) + h["proposalslink"] = Rails.application.routes.url_helpers.conference_proposal_url(conference.short_title, event, :host => CONFIG["url_for_emails"]) end h end diff --git a/config/config.yml.example b/config/config.yml.example index b5e79200..1a7a7abb 100644 --- a/config/config.yml.example +++ b/config/config.yml.example @@ -1,6 +1,10 @@ defaults: &defaults + # The sender address of emails + devise_mail_sender: no-reply@localhost # The hostname to be used when building the URL in the emails url_for_emails: localhost:3000 + # A secret key. You can generate one with 'rake secret' + devise_secret_key: 12345 development: <<: *defaults @@ -10,4 +14,3 @@ test: production: <<: *defaults - diff --git a/config/environment.rb b/config/environment.rb index d5b37271..8bfd6042 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,14 @@ # Load the rails application require File.expand_path('../application', __FILE__) +path = Rails.root.join("config", "config.yml") + +begin + CONFIG = YAML.load_file(path)[Rails.env] +rescue Exception + puts "Error while parsing config file #{path}" + CONFIG = Hash.new +end + # Initialize the rails application Osem::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index d3cc62d5..1b58a0d0 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,6 +1,9 @@ Osem::Application.configure do # Settings specified here will take precedence over those in config/application.rb + # Use letter_opener + config.action_mailer.delivery_method = :letter_opener + # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. @@ -35,5 +38,5 @@ Osem::Application.configure do # Expands the lines which load the assets config.assets.debug = true - config.action_mailer.default_url_options = { :host => 'localhost:3000' } + config.action_mailer.default_url_options = { :host => CONFIG['url_for_emails'] } end diff --git a/config/environments/production.rb b/config/environments/production.rb index d0afec8e..b27d2667 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -63,4 +63,7 @@ Osem::Application.configure do # Log the query plan for queries taking more than this (works # with SQLite, MySQL, and PostgreSQL) # config.active_record.auto_explain_threshold_in_seconds = 0.5 + + config.action_mailer.default_url_options = { :host => CONFIG['url_for_emails'] } + end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 72747fa5..edace139 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,10 +1,12 @@ # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| + # ==> Secret key + config.secret_key = CONFIG['devise_secret_key'] # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class with default "from" parameter. - config.mailer_sender = "no-reply@conference.opensuse.org" + config.mailer_sender = CONFIG['devise_mail_sender'] # Configure the class responsible to send e-mails. # config.mailer = "Devise::Mailer" diff --git a/config/initializers/osem.rb b/config/initializers/osem.rb deleted file mode 100644 index ae78358a..00000000 --- a/config/initializers/osem.rb +++ /dev/null @@ -1 +0,0 @@ -OSEM_CONFIG = YAML.load_file("#{Rails.root}/config/config.yml")[Rails.env]