@ -144,7 +144,6 @@ class ConferencesController < ApplicationController
if ! registration . nil?
if ! registration . nil?
session [ :registration ] = YAML . load ( registration . data )
session [ :registration ] = YAML . load ( registration . data )
session [ :registration ] [ :registration_id ] = registration . id
session [ :registration ] [ :registration_id ] = registration . id
puts 'XXXXXXXXXXXXXXXXXXXXXXXX'
next_step = ( registration . completed . blank? && registration . is_participant . present? ? 'organizations' : 'thanks' )
next_step = ( registration . completed . blank? && registration . is_participant . present? ? 'organizations' : 'thanks' )
else
else
if ! session [ :registration ] [ :user ] || ! session [ :registration ] [ :user ] [ :firstname ]
if ! session [ :registration ] [ :user ] || ! session [ :registration ] [ :user ] [ :firstname ]
@ -418,86 +417,189 @@ class ConferencesController < ApplicationController
is_post = request . post? || session [ :registration_step ]
is_post = request . post? || session [ :registration_step ]
set_conference
set_conference
if ! @conference . registration_open
if ! @this_ conference . registration_open
do_404
do_404
return
return
end
end
#if data[:next_step].blank?
set_conference_registration
# session.delete(:registration)
#end
data = register_submit
@register_template = nil
@register_step = is_post ? data [ :next_step ] : 'register'
@error_message = data [ :error ] ? data [ :message ] : nil
if logged_in?
template = ( @register_step == 'register' ? '' : 'register_' ) + @register_step
# if the user is logged in start them off on the policy
# page, unless they have already begun registration then
# start them off with questions
@register_template = @registration ? :questions : :policy
@name = current_user . firstname
# we should phase out last names
@name += " #{ current_user . lastname } " if current_user . lastname
end
# process data from the last view
case ( params [ :button ] || '' ) . to_sym
when :confirm_email
@register_template = :email_sent if is_post
when :policy
@register_template = :questions if is_post
when :save
if is_post
@registration || = ConferenceRegistration . new
@registration . conference_id = @this_conference . id
@registration . user_id = current_user . id
@registration . is_attending = 'yes'
@registration . is_confirmed = true
@registration . city = params [ :location ]
@registration . arrival = params [ :arrival ]
@registration . departure = params [ :departure ]
@registration . housing = params [ :housing ]
@registration . bike = params [ :bike ]
@registration . other = params [ :other ]
@registration . save
current_user . firstname = params [ :name ] . squish
current_user . lastname = nil
current_user . save
@register_template = @registration . registration_fees_paid ? :workshops : :payment
end
when :payment
if is_post && @registration
amount = params [ :amount ] . to_f
if amount
@registration . payment_confirmation_token = Digest :: SHA256 . hexdigest ( rand ( Time . now . to_f * 1000000 ) . to_i . to_s )
@registration . save
if ! File . exists? ( Rails . root . join ( " app " , " views " , params [ :controller ] , " _ #{ template } .html.haml " ) )
host = " #{ request . protocol } #{ request . host_with_port } "
do_404
response = PayPal ! . setup (
PayPalRequest ( amount ) ,
register_paypal_confirm_url ( @this_conference . slug , :paypal_confirm , @registration . payment_confirmation_token ) ,
register_paypal_confirm_url ( @this_conference . slug , :paypal_cancel , @registration . payment_confirmation_token )
)
redirect_to response . redirect_uri
return
return
end
end
@register_template = :workshops
end
when :paypal_confirm
if @registration && @registration . payment_confirmation_token == params [ :confirmation_token ]
if session [ :registration ]
if ENV [ 'RAILS_ENV' ] != 'test'
session [ :registration ] [ @register_step . to_sym ] || = Hash . new
# testing this does't work in test but it works in devo and prod
@registration . payment_info = { :payer_id = > params [ :PayerID ] , :token = > params [ :token ] , :amount = > PayPal ! . details ( params [ :token ] ) . amount . total } . to_yaml
end
end
@actions = nil
@multipart = false
#@registration.payment_confirmation_token = nil
case @register_step
@registration . save!
when 'register' , 'organizations' , 'new_organization' , 'new_workshop' , 'volunteer_questions'
@register_template = :workshops
@actions = :next
if @register_step == 'new_organization'
@multipart = true
end
end
when 'thanks'
when :paypal_cancel
@registration = ConferenceRegistration . find ( session [ :registration ] [ :registration_id ] )
if @registration
if @registration . is_confirmed . blank?
@registration . payment_confirmation_token = nil
@actions = :resend_confirmation_email
@registration . save
@register_template = :payment
end
end
next_step = 'thanks'
#if @registration.complete && @registration.is_participant && @registration.payment_info.nil?
#` @actions = [:submit_payment]
when 'primary'
@actions = [ :cancel , :next ]
when 'submit'
@actions = [ :cancel , :submit ]
when 'cancel'
@actions = [ :no , :yes ]
when 'confirm_payment'
@actions = [ :cancel_payment , :confirm_payment ]
when 'already_registered'
@registration = ConferenceRegistration . find_by ( :email = > session [ :registration ] [ :email ] )
if ! @registration . complete
@actions = :resend_confirmation_email
end
end
when 'questions'
@actions = [ :cancel , :submit ]
# prepare data for the next view
@housing_options = {
case @register_template
'I will fend for myself thanks' = > 'none' ,
when :questions
'I will need a real bed' = > 'bed' ,
@registration || = ConferenceRegistration . new (
'A couch or floor space will be fine' = > 'couch' ,
:conference_id = > @this_conference . id ,
'All I need is a backyard' = > 'camp'
:user_id = > current_user . id ,
:is_attending = > 'yes' ,
:is_confirmed = > true ,
:city = > view_context . location ( view_context . lookup_ip_location ) ,
:arrival = > @this_conference . start_date ,
:departure = > @this_conference . end_date ,
:housing = > nil ,
:bike = > nil ,
:other = > ''
) ;
when :workshops
@my_workshops = [ 1 , 2 , 3 , 4 ] . map { | i |
{
:title = > ( Forgery :: LoremIpsum . sentence ( { :random = > true } ) . gsub ( / \ .$ / , '' ) . titlecase ) ,
:info = > ( Forgery :: LoremIpsum . sentences ( rand ( 1 ... 5 ) , { :random = > true } ) )
}
}
session [ :registration ] [ :questions ] [ :housing ] || = 'couch'
@loaner_bike_options = {
'No' = > 'no' ,
'Yes, an average size should do' = > 'medium' ,
'Yes but a small one please' = > 'small' ,
'Yes but a large one please' = > 'large'
}
}
session [ :registration ] [ :questions ] [ :loaner_bike ] || = 'medium'
#session[:registration][:questions][:diet] ||= Hash.new
end
end
#puts ' ------yyyy----------------- '
#session.delete(:last_action)
#puts @register_step
# render :register
if request . xhr?
@register_content = render_to_string :partial = > template
# data = register_submit
render :json = > { status : 200 , html : @register_content }
# @register_step = is_post ? data[:next_step] : 'register'
else
# @error_message = data[:error] ? data[:message] : nil
@register_template = template
# template = (@register_step == 'register' ? '' : 'register_') + @register_step
render 'show'
end
# if !File.exists?(Rails.root.join("app", "views", params[:controller], "_#{template}.html.haml"))
# do_404
# return
# end
# if session[:registration]
# session[:registration][@register_step.to_sym] ||= Hash.new
# end
# @actions = nil
# @multipart = false
# case @register_step
# when 'register', 'organizations', 'new_organization', 'new_workshop', 'volunteer_questions'
# @actions = :next
# if @register_step == 'new_organization'
# @multipart = true
# end
# when 'thanks'
# @registration = ConferenceRegistration.find(session[:registration][:registration_id])
# if @registration.is_confirmed.blank?
# @actions = :resend_confirmation_email
# end
# next_step = 'thanks'
# #if @registration.complete && @registration.is_participant && @registration.payment_info.nil?
# #` @actions = [:submit_payment]
# when 'primary'
# @actions = [:cancel, :next]
# when 'submit'
# @actions = [:cancel, :submit]
# when 'cancel'
# @actions = [:no, :yes]
# when 'confirm_payment'
# @actions = [:cancel_payment, :confirm_payment]
# when 'already_registered'
# @registration = ConferenceRegistration.find_by(:email => session[:registration][:email])
# if !@registration.complete
# @actions = :resend_confirmation_email
# end
# when 'questions'
# @actions = [:cancel, :submit]
# @housing_options = {
# 'I will fend for myself thanks' => 'none',
# 'I will need a real bed' => 'bed',
# 'A couch or floor space will be fine' => 'couch',
# 'All I need is a backyard' => 'camp'
# }
# session[:registration][:questions][:housing] ||= 'couch'
# @loaner_bike_options = {
# 'No' => 'no',
# 'Yes, an average size should do' => 'medium',
# 'Yes but a small one please' => 'small',
# 'Yes but a large one please' => 'large'
# }
# session[:registration][:questions][:loaner_bike] ||= 'medium'
# #session[:registration][:questions][:diet] ||= Hash.new
# end
# if request.xhr?
# @register_content = render_to_string :partial => template
# render :json => {status: 200, html: @register_content}
# else
# @register_template = template
# render 'register'
# end
end
end
def registrations
def registrations
@ -571,9 +673,6 @@ class ConferencesController < ApplicationController
@conference_registration = ConferenceRegistration . find_by ( confirmation_token : params [ :confirmation_token ] )
@conference_registration = ConferenceRegistration . find_by ( confirmation_token : params [ :confirmation_token ] )
if ! @conference_registration . nil? && @conference_registration . conference_id == @conference . id && @conference_registration . complete && @conference_registration . payment_info . nil?
if ! @conference_registration . nil? && @conference_registration . conference_id == @conference . id && @conference_registration . complete && @conference_registration . payment_info . nil?
session [ :registration ] = YAML . load ( @conference_registration . data )
session [ :registration ] = YAML . load ( @conference_registration . data )
session [ :registration ] [ :registration_id ] = @conference_registration . id
session [ :registration ] [ :path ] = Array . new
session [ :registration_step ] = 'paypal-cancelled'
redirect_to action : 'register'
redirect_to action : 'register'
end
end
end
end
@ -639,9 +738,9 @@ class ConferencesController < ApplicationController
private
private
# Use callbacks to share common setup or constraints between actions.
# Use callbacks to share common setup or constraints between actions.
def set_conference
def set_conference
@conference = nil
@this_ conference = nil
if type = ConferenceType . find_by! ( slug : params [ :conference_type ] || params [ :conference_type_slug ] || 'bikebike' )
if type = ConferenceType . find_by! ( slug : params [ :conference_type ] || params [ :conference_type_slug ] || 'bikebike' )
if @conference = Conference . find_by! ( slug : params [ :conference_slug ] || params [ :slug ] , conference_type_id : type . id )
if @this_ conference = Conference . find_by! ( slug : params [ :conference_slug ] || params [ :slug ] , conference_type_id : type . id )
set_conference_registration
set_conference_registration
end
end
end
end
@ -651,12 +750,7 @@ class ConferencesController < ApplicationController
end
end
def set_conference_registration
def set_conference_registration
if ! @conference || ! current_user
@registration = logged_in? ? ConferenceRegistration . find_by ( :user_id = > current_user . id , :conference_id = > @this_conference . id ) : nil
@conference_registration = nil
return
end
@conference_registration = ConferenceRegistration . find_by ( conference_id : @conference . id , user_id : current_user . id )
end
end
# Only allow a trusted parameter "white list" through.
# Only allow a trusted parameter "white list" through.
@ -807,11 +901,10 @@ class ConferencesController < ApplicationController
end
end
def PayPal!
def PayPal!
paypal_info = get_secure_info ( :paypal )
Paypal :: Express :: Request . new (
Paypal :: Express :: Request . new (
:username = > paypal_info [ :username ] ,
:username = > @this_conference . paypal_username ,
:password = > paypal_info [ :password ] ,
:password = > @this_conference . paypal_password ,
:signature = > paypal_info [ :signature ]
:signature = > @this_conference . paypal_signature
)
)
end
end