Sha256: e59fc4301c7caa0c8433c9de36530563543706ea78550b16dd8a1e25c7cb286e

Contents?: true

Size: 1.93 KB

Versions: 13

Compression:

Stored size: 1.93 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:))

        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] = t("error", scope: "decidim.devise.registrations.create")
            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

13 entries across 13 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.28.4 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.29.0 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.28.3 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.29.0.rc4 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.29.0.rc3 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.29.0.rc2 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.29.0.rc1 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.28.2 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.28.1 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.28.0 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.28.0.rc5 app/controllers/decidim/devise/registrations_controller.rb
decidim-core-0.28.0.rc4 app/controllers/decidim/devise/registrations_controller.rb