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 /app/controllers/users | |
| parent | 8bf59df0653ed0cc0ac6ac76ccfb7d99628ebf85 (diff) | |
| download | chouette-core-8e7b4174cf9b3036e440b0364ee60e2dc968835c.tar.bz2 | |
Devise User : add namespace controllers and use devise methods
Diffstat (limited to 'app/controllers/users')
| -rw-r--r-- | app/controllers/users/invitations_controller.rb | 11 | ||||
| -rw-r--r-- | app/controllers/users/registrations_controller.rb | 45 | 
2 files changed, 56 insertions, 0 deletions
diff --git a/app/controllers/users/invitations_controller.rb b/app/controllers/users/invitations_controller.rb new file mode 100644 index 000000000..ab7f77baf --- /dev/null +++ b/app/controllers/users/invitations_controller.rb @@ -0,0 +1,11 @@ +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 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  | 
