Sha256: fe62b2d5b4e7aa5a1830e1686ec2345bbe3c2f18e5285033c340d07a975a2082

Contents?: true

Size: 1.34 KB

Versions: 13

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module Decidim
  # A command with all the business logic to create a user through the sign up form.
  class CreateRegistration < Decidim::Command
    # Public: Initializes the command.
    #
    # form - A form object with the params.
    def initialize(form)
      @form = form
    end

    # Executes the command. Broadcasts these events:
    #
    # - :ok when everything is valid.
    # - :invalid if the form was not valid and we could not proceed.
    #
    # Returns nothing.
    def call
      if form.invalid?
        user = User.has_pending_invitations?(form.current_organization.id, form.email)
        user.invite!(user.invited_by) if user
        return broadcast(:invalid)
      end

      create_user

      broadcast(:ok, @user)
    rescue ActiveRecord::RecordInvalid
      broadcast(:invalid)
    end

    private

    attr_reader :form

    def create_user
      @user = User.create!(
        email: form.email,
        name: form.name,
        nickname: form.nickname,
        password: form.password,
        password_updated_at: Time.current,
        organization: form.current_organization,
        tos_agreement: form.tos_agreement,
        newsletter_notifications_at: form.newsletter_at,
        accepted_tos_version: form.current_organization.tos_version,
        locale: form.current_locale
      )
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

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