diff options
| author | Luc Donnet | 2014-10-31 15:47:24 +0100 |
|---|---|---|
| committer | Luc Donnet | 2014-10-31 15:47:24 +0100 |
| commit | c9fd03422743d3d716bbd7199184c035c1b0d4c9 (patch) | |
| tree | 291c67ac01b05b91d9c998edbfdf0528f3ed45be | |
| parent | 85d72f54aaba1f1eca474abbf3923a9528a68625 (diff) | |
| download | chouette-core-c9fd03422743d3d716bbd7199184c035c1b0d4c9.tar.bz2 | |
Fix devise flash message when signin and refuse user creation if Rails config not accepts Refs #0029417
| -rw-r--r-- | app/controllers/registrations_controller.rb | 17 | ||||
| -rw-r--r-- | app/models/user.rb | 4 | ||||
| -rw-r--r-- | app/views/devise/_links.erb | 2 | ||||
| -rw-r--r-- | app/views/devise/registrations/new.html.erb | 7 | ||||
| -rw-r--r-- | config/environments/development.rb | 4 | ||||
| -rw-r--r-- | config/environments/production.rb | 3 | ||||
| -rw-r--r-- | config/initializers/devise.rb | 22 | ||||
| -rw-r--r-- | config/locales/devise.en.yml | 1 | ||||
| -rw-r--r-- | config/locales/devise.fr.yml | 1 | ||||
| -rw-r--r-- | config/routes.rb | 27 |
10 files changed, 57 insertions, 31 deletions
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb new file mode 100644 index 000000000..f0ac420ce --- /dev/null +++ b/app/controllers/registrations_controller.rb @@ -0,0 +1,17 @@ + class RegistrationsController < Devise::RegistrationsController + + prepend_before_filter :accept_user_creation, :only => [:new, :create] + + private + + def accept_user_creation + puts "J'y passe" + if !Rails.application.config.accept_user_creation + redirect_to root_path + return false + else + return true + end + end + + end diff --git a/app/models/user.rb b/app/models/user.rb index ae6cceeee..1889a3bf0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,9 +6,11 @@ class User < ActiveRecord::Base :confirmable, :invitable # Setup accessible (or protected) attributes for your model - attr_accessible :email, :password, :current_password, :password_confirmation, :remember_me, :name + attr_accessible :email, :password, :current_password, :password_confirmation, :remember_me, :name, :organisation_attributes belongs_to :organisation + + accepts_nested_attributes_for :organisation validates_presence_of :email validates_presence_of :name diff --git a/app/views/devise/_links.erb b/app/views/devise/_links.erb index 3381b2e8e..e2a1bf3ef 100644 --- a/app/views/devise/_links.erb +++ b/app/views/devise/_links.erb @@ -7,7 +7,7 @@ </li> <li> - <%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%- if devise_mapping.registerable? && controller_name != 'registrations' && Rails.application.config.accept_user_creation %> <%= link_to t(".sign_up"), new_registration_path(resource_name) %><br /> <% end -%> </li> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index d18db9402..79edcb53b 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -1,10 +1,13 @@ <%= title_tag t('.title') %> <%= semantic_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |form| %> - <%= form.inputs do %> + <%= form.inputs do %> + <%= form.semantic_fields_for :organisation, Organisation.new do |organisation| %> + <%= organisation.input :name, :label => t("helpers.label.user.organisation_name") %> + <% end %> <% if resource.respond_to?( :name) %> <%= form.input :name %> - <% end %> + <% end %> <%= form.input :email %> <%= form.input :password, :as => :password %> <%= form.input :password_confirmation, :as => :password %> diff --git a/config/environments/development.rb b/config/environments/development.rb index 2c028ac58..0d33ac03c 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -52,11 +52,13 @@ ChouetteIhm::Application.configure do config.company_name = "afimb" config.company_theme = "#61970b" # AFIMB color config.company_contact = "http://www.chouette.mobi/contact-support/" - + config.accept_user_creation = true + # CITYWAY # config.company_name = "cityway" # config.company_theme = "#32adb0" # config.company_contact = "http://www.cityway.fr/contact/?rub_code=14" + # config.accept_user_creation = false # file to data for demo config.demo_data = "tmp/demo.zip" diff --git a/config/environments/production.rb b/config/environments/production.rb index 8badf096a..765ff8227 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -137,12 +137,13 @@ ChouetteIhm::Application.configure do config.company_name = "afimb" config.company_theme = "#61970b" # AFIMB color config.company_contact = "http://www.chouette.mobi/contact-support/" + config.accept_user_creation = true # CITYWAY # config.company_name = "cityway" # config.company_theme = "#32adb0" # config.company_contact = "http://www.cityway.fr/contact/?rub_code=14" - + # config.accept_user_creation = false # file to data for demo config.demo_data = ENV['CHOUETTE_DEMO_DATA'].nil? ? "/path/to/demo.zip" : ENV['CHOUETTE_DEMO_DATA'] diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index ef5c89fbf..4aa6ef80d 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -242,25 +242,3 @@ Devise.setup do |config| # manager.default_strategies(:scope => :user).unshift :some_external_strategy # end end - -# class Devise::FailureApp -# def return_to_root_path? -# root_path == session["#{scope}_return_to"] -# end -# def redirect -# store_location! -# if flash[:timedout] && flash[:alert] -# flash.keep(:timedout) -# flash.keep(:alert) -# else -# Rails.logger.debug "A" * 30 -# Rails.logger.debug i18n_message -# Rails.logger.debug redirect_url -# Rails.logger.debug scope -# Rails.logger.debug root_path -# Rails.logger.debug session["#{scope}_return_to"] -# flash[:alert] = i18n_message unless return_to_root_path? -# end -# redirect_to redirect_url -# end -# end diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml index 4fb3980f1..0a42a021d 100644 --- a/config/locales/devise.en.yml +++ b/config/locales/devise.en.yml @@ -36,6 +36,7 @@ en: helpers: label: user: + organisation_name: "Organisation name" name: Full name password: Password password_confirmation: Password confirmation diff --git a/config/locales/devise.fr.yml b/config/locales/devise.fr.yml index b1a9a743a..d3a60d9a0 100644 --- a/config/locales/devise.fr.yml +++ b/config/locales/devise.fr.yml @@ -40,6 +40,7 @@ fr: helpers: label: user: + organisation_name: "Nom de l'organisation" name: Nom complet password: Mot de passe password_confirmation: Confirmation du mot de passe diff --git a/config/routes.rb b/config/routes.rb index 827ee97a1..f629a963f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,31 @@ ChouetteIhm::Application.routes.draw do devise_scope :users do - match "/users/sign_up" => "subscriptions#new" + #match "/users/sign_up" => "subscriptions#new", end - devise_for :users + devise_for :users, :controllers => { :registrations => "registrations" } + + devise_scope :user do + authenticated :user do + root :to => 'referentials#index' + end + + unauthenticated do + root :to => 'devise/sessions#new' + end + end + + # Rails 4 syntax + # devise_for :users + # devise_scope :user do + # authenticated :user do + # root :to => 'referentials#index', as: :authenticated_root + # end + # unauthenticated :user do + # root :to => 'devise/registrations#new', as: :unauthenticated_root + # end + # end + namespace :api do namespace :v1 do @@ -188,5 +210,4 @@ ChouetteIhm::Application.routes.draw do match '/422', :to => 'errors#server_error' match '/500', :to => 'errors#server_error' - root :to => 'referentials#index' end |
