Class: DmEvent::RegistrationsController

Inherits:
ApplicationController show all
Includes:
DmCore::LiquidHelper, DmCore::UrlHelper, PermittedParams, OffsitePayments::Integrations
Defined in:
app/controllers/dm_event/registrations_controller.rb

Instance Method Summary collapse

Methods included from PermittedParams

#registration_params, #system_email_params, #workshop_params, #workshop_price_params

Instance Method Details

#choose_paymentObject

Only allow to proceed with payment if the registration is still in pending




63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/dm_event/registrations_controller.rb', line 63

def choose_payment
  @registration = Registration.find_by_uuid(params[:uuid])
  @workshop     = @registration.workshop if @registration
  flash[:alert] = I18n.t('core.resource_invalid')
  redirect_to main_app.root_url and return if @registration.nil? || !@registration.accepted?

  if @workshop.
    raise Account::LoginRequired.new(I18n.t('core.login_required')) if current_user.nil?
    if @registration..user != current_user && !is_admin?
      flash[:alert] = I18n.t('core.resource_invalid')
      redirect_to main_app.root_url and return
    end
  end
end

#createObject




39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/dm_event/registrations_controller.rb', line 39

def create
  redirect_to(action: :new) and return if @workshop. && current_user.nil?
  
  profile_params                  = params[:registration].delete("user_profile_attributes") if params[:registration]
  profile_params.delete(:id)      if profile_params
  
  @registration                   = @workshop.registrations.new(registration_params(@workshop))
  @registration.registered_locale = I18n.locale
  @registration.      = current_user ? current_user. : UserProfile.new
  @registration..assign_attributes((profile_params)) unless profile_params.blank?

  if @registration.save
    if @workshop.payments_enabled? && !@workshop.require_review? && @registration.balance_owed.positive?
      redirect_to register_choose_payment_url(@registration.uuid)
    else
      redirect_to register_success_url(@registration.uuid)
    end
  else
    render action: :new
  end
end

#newObject




18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/dm_event/registrations_controller.rb', line 18

def new
  redirect_to main_app.root_url and return if @workshop.nil?
  
  if !@workshop.registration_closed? || is_admin?
    @registration               = @workshop.registrations.build
    @registration.  = current_user ? current_user. : UserProfile.new
    
    if @workshop.require_address && !@registration..address_valid?
      #--- address is required and there are missing fields in the profile
      @registration..address_required = true
    end
    @registration..userless_registration = true if current_user.nil? && !@workshop.

    set_meta description: @workshop.summary, "og:description" => sanitize_text(markdown(@workshop.summary, safe: false))
    set_meta "og:image" => site_asset_media_url(@workshop.image) if @workshop.image.present?
  else
    render action: :closed
  end
end

#successObject

Success page for a registration. Look up the uuid and display success. Can do this many times - if the user doesn’t own the registration, then kick them out.




82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/dm_event/registrations_controller.rb', line 82

def success
  @registration = Registration.find_by_uuid(params[:uuid])
  if @registration.nil? || @registration..user != current_user
    #--- not logged in or not the users registration (for )
    flash[:alert] = I18n.t('core.resource_invalid')
    redirect_to main_app.root_url and return
  end
  @workshop         = @registration.workshop if @registration
  @receipt_content  = @registration.email_state_notification(@registration.current_state, false) || ""
end