diff options
| author | anicet | 2015-06-09 09:54:08 +0200 |
|---|---|---|
| committer | anicet | 2015-06-09 10:33:38 +0200 |
| commit | 8e7b4174cf9b3036e440b0364ee60e2dc968835c (patch) | |
| tree | 7b8f6641af13b42cc8667c5f208698b2892349d8 | |
| parent | 8bf59df0653ed0cc0ac6ac76ccfb7d99628ebf85 (diff) | |
| download | chouette-core-8e7b4174cf9b3036e440b0364ee60e2dc968835c.tar.bz2 | |
Devise User : add namespace controllers and use devise methods
| -rw-r--r-- | app/controllers/registrations_controller.rb | 33 | ||||
| -rw-r--r-- | app/controllers/users/invitations_controller.rb (renamed from app/controllers/invitations_controller.rb) | 8 | ||||
| -rw-r--r-- | app/controllers/users/registrations_controller.rb | 45 | ||||
| -rw-r--r-- | config/routes.rb | 4 |
4 files changed, 51 insertions, 39 deletions
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb deleted file mode 100644 index 673f52436..000000000 --- a/app/controllers/registrations_controller.rb +++ /dev/null @@ -1,33 +0,0 @@ - class RegistrationsController < Devise::RegistrationsController - - prepend_before_filter :accept_user_creation, :only => [:new, :create] - - protected - - # The default url to be used after updating a resource. You need to overwrite - # this method in your own RegistrationsController. - def after_update_path_for(resource) - organisation_user_path(resource) - end - - def sign_up_params - params.require(:user).permit(:name, :email, :password, :password_confirmation, { organisation_attributes: [:name] } ) - end - - def account_update_params - params.require(:user).permit(:name, :email, :password, :password_confirmation, :current_password) - end - - - private - - def accept_user_creation - if !Rails.application.config.accept_user_creation - redirect_to unauthenticated_root_path - return false - else - return true - end - end - - end diff --git a/app/controllers/invitations_controller.rb b/app/controllers/users/invitations_controller.rb index 4b5567f0c..ab7f77baf 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/users/invitations_controller.rb @@ -1,13 +1,11 @@ -class InvitationsController < Devise::InvitationsController - +class Users::InvitationsController < Devise::InvitationsController protected - + def invite_params params.require(:user).permit(:name, :email, :organisation_id ) end def update_resource_params params.require(:user).permit(:name, :email, :password, :password_confirmation, :invitation_token) - end - + end end diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb new file mode 100644 index 000000000..d86e66a09 --- /dev/null +++ b/app/controllers/users/registrations_controller.rb @@ -0,0 +1,45 @@ +class Users::RegistrationsController < Devise::RegistrationsController + before_filter :configure_sign_up_params, only: [:create] + before_filter :configure_account_update_params, only: [:update] + + prepend_before_filter :accept_user_creation, :only => [:new, :create] + + protected + + def configure_sign_up_params + devise_parameter_sanitizer.for(:sign_up).push( + :name, + :email, + :password, + :password_confirmation, + organisation_attributes: [:name] + ) + end + + def configure_account_update_params + devise_parameter_sanitizer.for(:account_update).push( + :name, + :email, + :password, + :password_confirmation, + :current_password + ) + end + + # The default url to be used after updating a resource. You need to overwrite + # this method in your own RegistrationsController. + def after_update_path_for(resource) + organisation_user_path(resource) + end + + private + + def accept_user_creation + if !Rails.application.config.accept_user_creation + redirect_to unauthenticated_root_path + return false + else + return true + end + end +end diff --git a/config/routes.rb b/config/routes.rb index e0843fba3..29ef9eff1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,8 @@ ChouetteIhm::Application.routes.draw do - devise_for :users, :controllers => { :registrations => "registrations", :invitations => 'invitations' } + devise_for :users, :controllers => { + :registrations => 'users/registrations', :invitations => 'users/invitations' + } devise_scope :user do authenticated :user do |
