Sha256: b877cab7ac849e6a75db6bae6b45d4330ed62cf5ccba900d8fe82da3ec75e935

Contents?: true

Size: 1.96 KB

Versions: 6

Compression:

Stored size: 1.96 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
      include NeedsTosAccepted

      helper Decidim::PasswordsHelper

      before_action :check_sign_up_enabled
      before_action :configure_permitted_parameters

      invisible_captcha

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

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

        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
            flash.now[:alert] = @form.errors.full_messages.join(", ") if @form.errors.full_messages.any?
            render :new
          end
        end
      end

      protected

      def check_sign_up_enabled
        redirect_to new_user_session_path unless current_organization.sign_up_enabled?
      end

      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

      def devise_mapping
        ::Devise.mappings[:user]
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-core-0.27.4 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.27.3 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.27.2 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.27.1 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.27.0 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.27.0.rc2 app/controllers/decidim/devise/registrations_controller.rb