Sha256: 5ee121678dfb085e6e8499df43ea7ee5a4e63e7264b1d20a5521b430ddd77419
Contents?: true
Size: 1.36 KB
Versions: 5
Compression:
Stored size: 1.36 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 wasn't valid and we couldn't 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_confirmation: form.password_confirmation, 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
5 entries across 5 versions & 1 rubygems