Sha256: aee1678313be807ecfcc7b1255f6dc76e9ea5bf6f228677533667ca2e5e97d4c

Contents?: true

Size: 1.79 KB

Versions: 16

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

module Decidim
  module Devise
    # This controller customizes the behaviour of Devise's
    # RegistrationsController so we can specify a custom layout.
    class RegistrationsController < ::Devise::RegistrationsController
      include FormFactory
      include Decidim::DeviseControllers

      helper_method :terms_and_conditions_page

      before_action :configure_permitted_parameters
      helper_method :terms_and_conditions_page

      invisible_captcha

      def new
        @form = form(RegistrationForm).from_params(
          user: {
            sign_up_as: "user"
          }
        )
      end

      def create
        @form = form(RegistrationForm).from_params(params[:user])

        CreateRegistration.call(@form) do
          on(:ok) do |user|
            if user.active_for_authentication?
              set_flash_message! :notice, :signed_up
              sign_up(:user, user)
              respond_with user, location: after_sign_up_path_for(user)
            else
              set_flash_message! :notice, :"signed_up_but_#{user.inactive_message}"
              expire_data_after_sign_in!
              respond_with user, location: after_inactive_sign_up_path_for(user)
            end
          end

          on(:invalid) do
            render :new
          end
        end
      end

      private

      def terms_and_conditions_page
        @terms_and_conditions_page ||= Decidim::StaticPage.find_by(slug: "terms-and-conditions")
      end

      protected

      def configure_permitted_parameters
        devise_parameter_sanitizer.permit(:sign_up, keys: [:name, :tos_agreement])
      end

      # Called before resource.save
      def build_resource(hash = nil)
        super(hash)
        resource.organization = current_organization
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
decidim-core-0.10.1 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.10.0 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.9.3 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.9.2 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.9.1 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.9.0 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.8.4 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.8.3 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.8.2 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.8.1 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.8.0 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.7.4 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.7.3 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.7.2 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.7.1 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.7.0 app/controllers/decidim/devise/registrations_controller.rb