User/Person models merge
This commit is contained in:
parent
66b84e3660
commit
23bf55b66c
80 changed files with 1064 additions and 1221 deletions
|
|
@ -5,35 +5,32 @@ class ConferenceRegistrationController < ApplicationController
|
|||
# TODO Figure out how to change the route's id from :id to :conference_id
|
||||
@conference = Conference.find_by(short_title: params[:id])
|
||||
@workshops = @conference.events.where("require_registration = ? AND state LIKE ?", true, 'confirmed')
|
||||
@person = current_user.person
|
||||
if @person.first_name.blank? || @person.last_name.blank?
|
||||
redirect_to(edit_user_registration_path, :alert => "Please fill in your first and last name before registering.")
|
||||
return
|
||||
end
|
||||
@registration = @person.registrations.where(:conference_id => @conference.id).first
|
||||
@user = current_user
|
||||
|
||||
@registration = @user.registrations.where(:conference_id => @conference.id).first
|
||||
@registered = true
|
||||
if @registration.nil?
|
||||
@registered = false
|
||||
@registration = @person.registrations.new(:conference_id => @conference.id)
|
||||
@registration = @user.registrations.new(:conference_id => @conference.id)
|
||||
end
|
||||
|
||||
# Check if there's an existing SupporterRegistration for this email and link it when appropriate
|
||||
@registration.supporter_registration ||= @conference.supporter_registrations.where(:email => @person.email).first
|
||||
@registration.supporter_registration ||= @conference.supporter_registrations.where(:email => @user.email).first
|
||||
@registration.supporter_registration ||= SupporterRegistration.new(:conference_id => @conference.id)
|
||||
end
|
||||
|
||||
# TODO this is ugly
|
||||
def update
|
||||
conference = Conference.find_by(short_title: params[:id])
|
||||
person = current_user.person
|
||||
registration = person.registrations.where(:conference_id => conference.id).first
|
||||
user = current_user
|
||||
registration = user.registrations.where(:conference_id => conference.id).first
|
||||
update_registration = true
|
||||
# First verify that the supporter code is legit
|
||||
if !params[:registration][:supporter_registration_attributes].nil? && !params[:registration][:supporter_registration_attributes][:code].empty?
|
||||
regs = conference.supporter_registrations.where(:code => params[:registration][:supporter_registration_attributes][:code])
|
||||
|
||||
if regs.count != 0
|
||||
if regs.where(:email => person.email).count == 0
|
||||
if regs.where(:email => user.email).count == 0
|
||||
redirect_to(register_conference_path(:id => conference.short_title), :alert => "This code is already in use. Please contact #{conference.contact_email} for assistance.")
|
||||
return
|
||||
end
|
||||
|
|
@ -42,16 +39,16 @@ class ConferenceRegistrationController < ApplicationController
|
|||
begin
|
||||
if registration.nil?
|
||||
update_registration = false
|
||||
person.update_attributes(registration_params[:person_attributes])
|
||||
params[:registration].delete :person_attributes
|
||||
user.update_attributes(registration_params[:user_attributes])
|
||||
params[:registration].delete :user_attributes
|
||||
supporter_reg = params[:registration][:supporter_registration_attributes]
|
||||
params[:registration].delete :supporter_registration_attributes
|
||||
registration = person.registrations.new(registration_params)
|
||||
registration = user.registrations.new(registration_params)
|
||||
if conference.use_supporter_levels? && !supporter_reg.nil?
|
||||
if !supporter_reg[:id].blank?
|
||||
# This means that their supporter registration was entered ahead of time, probably by an admin
|
||||
registration.supporter_registration = SupporterRegistration.find(supporter_reg[:id])
|
||||
if registration.supporter_registration.email != person.email
|
||||
if registration.supporter_registration.email != user.email
|
||||
raise "Invalid code"
|
||||
end
|
||||
else
|
||||
|
|
@ -78,7 +75,7 @@ class ConferenceRegistrationController < ApplicationController
|
|||
# Track ahoy event
|
||||
ahoy.track 'Registered', title: 'New registration'
|
||||
if conference.email_settings.send_on_registration?
|
||||
Mailbot.registration_mail(conference, current_user.person).deliver
|
||||
Mailbot.registration_mail(conference, current_user).deliver
|
||||
end
|
||||
end
|
||||
redirect_to(register_conference_path(:id => conference.short_title), :notice => redirect_message)
|
||||
|
|
@ -86,8 +83,8 @@ class ConferenceRegistrationController < ApplicationController
|
|||
|
||||
def unregister
|
||||
conference = Conference.find_by(short_title: params[:id])
|
||||
person = current_user.person
|
||||
registration = person.registrations.where(:conference_id => conference.id).first
|
||||
user = current_user
|
||||
registration = user.registrations.where(:conference_id => conference.id).first
|
||||
registration.destroy
|
||||
redirect_to :root
|
||||
end
|
||||
|
|
@ -106,9 +103,8 @@ class ConferenceRegistrationController < ApplicationController
|
|||
vchoice_ids: [],
|
||||
qanswer_ids: [],
|
||||
qanswers_attributes: [],
|
||||
person_attributes: [
|
||||
:id, :public_name, :mobile, :tshirt, :languages,
|
||||
:volunteer_experience],
|
||||
user_attributes: [
|
||||
:id, :name],
|
||||
supporter_registration_attributes: [
|
||||
:id, :supporter_level_id, :code
|
||||
])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue