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 /app | |
| 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
Diffstat (limited to 'app')
| -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 |
4 files changed, 26 insertions, 4 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 %> |
