2013-01-07 09:04:09 +01:00
|
|
|
class ConferenceRegistrationController < ApplicationController
|
|
|
|
|
before_filter :verify_user
|
|
|
|
|
|
|
|
|
|
def register
|
|
|
|
|
# TODO Figure out how to change the route's id from :id to :conference_id
|
|
|
|
|
@conference = Conference.find_all_by_short_title(params[:id]).first
|
|
|
|
|
@person = current_user.person
|
|
|
|
|
@registration = @person.registrations.where(:conference_id => @conference.id).first
|
|
|
|
|
@registered = true
|
|
|
|
|
if @registration.nil?
|
|
|
|
|
@registered = false
|
|
|
|
|
@registration = @person.registrations.new(:conference_id => @conference.id)
|
|
|
|
|
end
|
2013-02-02 16:43:47 +01:00
|
|
|
|
2013-02-03 18:12:44 +01:00
|
|
|
@registration.supporter_registration ||= SupporterRegistration.new(:conference_id => @conference.id)
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
|
|
|
|
|
2013-01-14 08:49:49 +01:00
|
|
|
# TODO this is ugly
|
2013-01-07 09:04:09 +01:00
|
|
|
def update
|
|
|
|
|
conference = Conference.find_all_by_short_title(params[:id]).first
|
|
|
|
|
person = current_user.person
|
|
|
|
|
registration = person.registrations.where(:conference_id => conference.id).first
|
|
|
|
|
update_registration = true
|
|
|
|
|
begin
|
|
|
|
|
if registration.nil?
|
|
|
|
|
update_registration = false
|
|
|
|
|
person.update_attributes(params[:registration][:person_attributes])
|
|
|
|
|
params[:registration].delete :person_attributes
|
2013-02-03 18:12:44 +01:00
|
|
|
params[:registration][:supporter_registration_attributes]["conference_id"] = conference.id
|
2013-01-07 09:04:09 +01:00
|
|
|
registration = person.registrations.new(params[:registration])
|
|
|
|
|
registration.conference_id = conference.id
|
|
|
|
|
registration.save!
|
|
|
|
|
else
|
|
|
|
|
registration.update_attributes!(params[:registration])
|
|
|
|
|
end
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
redirect_to(register_conference_path(:id => conference.short_title), :alert => 'Registration failed:' + e.message)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
redirect_message = "You are now registered."
|
|
|
|
|
if update_registration
|
|
|
|
|
redirect_message = "Registration updated."
|
2013-01-14 08:49:49 +01:00
|
|
|
else
|
2013-01-17 13:56:05 +01:00
|
|
|
Mailbot.registration_mail(conference, current_user.person).deliver
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
|
|
|
|
redirect_to(register_conference_path(:id => conference.short_title), :notice => redirect_message)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def unregister
|
|
|
|
|
conference = Conference.find_all_by_short_title(params[:id]).first
|
|
|
|
|
person = current_user.person
|
|
|
|
|
registration = person.registrations.where(:conference_id => conference.id).first
|
|
|
|
|
registration.destroy
|
|
|
|
|
redirect_to :root
|
|
|
|
|
end
|
|
|
|
|
end
|