fix new registration, add check if user/person exists but is not registered
This commit is contained in:
parent
6fc6e924ef
commit
e4cc6f158f
2 changed files with 56 additions and 43 deletions
|
|
@ -41,8 +41,10 @@ class Admin::RegistrationsController < ApplicationController
|
||||||
begin
|
begin
|
||||||
@person.update_attributes!(params[:registration][:person_attributes])
|
@person.update_attributes!(params[:registration][:person_attributes])
|
||||||
params[:registration].delete :person_attributes
|
params[:registration].delete :person_attributes
|
||||||
@registration.supporter_registration = @conference.supporter_registrations.new(params[:registration][:supporter_registration_attributes])
|
if params[:registration][:supporter_registration]
|
||||||
params[:registration].delete :supporter_registration_attributes
|
@registration.supporter_registration.update_attributes(params[:registration][:supporter_registration_attributes])
|
||||||
|
params[:registration].delete :supporter_registration_attributes
|
||||||
|
end
|
||||||
@registration.update_attributes!(params[:registration])
|
@registration.update_attributes!(params[:registration])
|
||||||
flash[:notice] = "Successfully updated registration for #{@person.public_name} #{@person.email}"
|
flash[:notice] = "Successfully updated registration for #{@person.public_name} #{@person.email}"
|
||||||
redirect_to(admin_conference_registrations_path(@conference.short_title))
|
redirect_to(admin_conference_registrations_path(@conference.short_title))
|
||||||
|
|
@ -54,50 +56,62 @@ class Admin::RegistrationsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@registration = Registration.new
|
@user = User.new
|
||||||
|
@person = Person.new
|
||||||
|
@registration = @person.registrations.new
|
||||||
|
@supporter_registration = @conference.supporter_registrations.new
|
||||||
@conference = Conference.find_all_by_short_title(params[:conference_id]).first
|
@conference = Conference.find_all_by_short_title(params[:conference_id]).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@conference = Conference.find_all_by_short_title(params[:conference_id]).first
|
@conference = Conference.find_all_by_short_title(params[:conference_id]).first
|
||||||
|
person = Person.where("email LIKE ?", params[:registration][:user][:email]).first
|
||||||
|
|
||||||
if params[:registration][:people][:first_name].blank? || params[:registration][:people][:last_name].blank?
|
if !person.nil?
|
||||||
redirect_to(:back, :alert => "Please fill in your first and last name before registering.")
|
reg = @conference.registrations.where("person_id = ?", person.id).first
|
||||||
return
|
if reg.nil?
|
||||||
end
|
|
||||||
|
|
||||||
user = User.new
|
|
||||||
user.email = params[:registration][:user][:email]
|
|
||||||
user.password = params[:registration][:user][:password]
|
|
||||||
begin
|
|
||||||
user.save!
|
|
||||||
user.skip_confirmation!
|
|
||||||
person = Person.where("user_id = ?", user.id).first
|
|
||||||
person.update_attributes(params[:registration][:people])
|
|
||||||
begin
|
|
||||||
params[:registration].delete :people
|
|
||||||
params[:registration].delete :user
|
|
||||||
|
|
||||||
registration = person.registrations.new
|
registration = person.registrations.new
|
||||||
registration.supporter_registration = @conference.supporter_registrations.new(:supporter_level_id => params[:registration][:supporter_registrations][:supporter_level], :code => params[:registration][:supporter_registrations][:code], :email => person.email, :name => person.public_name)
|
else
|
||||||
params[:registration].delete :supporter_registrations
|
|
||||||
|
|
||||||
registration.update_attributes(params[:registration])
|
|
||||||
registration.update_attributes(:conference_id => @conference.id, :attended => true)
|
|
||||||
registration.save!
|
|
||||||
|
|
||||||
redirect_to admin_conference_registrations_path(@conference.short_title)
|
redirect_to admin_conference_registrations_path(@conference.short_title)
|
||||||
flash[:notice] = "Successfully created new registration for #{person.email}."
|
flash[:notice] = "#{person.email} is already registred!"
|
||||||
# rescue Exception => e
|
return
|
||||||
# user.destroy
|
end
|
||||||
# person.destroy
|
else
|
||||||
# redirect_to(:back, :alert => "Did not create registration. #{e.message}")
|
if params[:registration][:person][:first_name].blank? || params[:registration][:person][:last_name].blank?
|
||||||
# return
|
redirect_to(:back, :alert => "Please fill in your first and last name before registering.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
user = User.new
|
||||||
|
user.email = params[:registration][:user][:email]
|
||||||
|
user.password = rand(36**6).to_s(36)
|
||||||
|
begin user.save!
|
||||||
|
user.skip_confirmation!
|
||||||
|
person = Person.where("user_id = ?", user.id).first
|
||||||
|
person.update_attributes(params[:registration][:person])
|
||||||
|
begin
|
||||||
|
registration = person.registrations.new
|
||||||
|
if params[:registration][:supporter_registration]
|
||||||
|
registration.supporter_registration = @conference.supporter_registrations.new(:supporter_level_id => params[:registration][:supporter_registration][:supporter_level_id], :code => params[:registration][:supporter_registration][:code], :email => person.email, :name => person.public_name)
|
||||||
|
end
|
||||||
|
rescue Exception => e
|
||||||
|
user.destroy
|
||||||
|
person.destroy
|
||||||
|
redirect_to(:back, :alert => "Did not create registration. #{e.message}")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
rescue Exception => e
|
||||||
|
redirect_to(:back, :alert => "Did not create new user/person. #{e.message}")
|
||||||
|
return
|
||||||
end
|
end
|
||||||
# rescue Exception => e
|
|
||||||
# redirect_to(:back, :alert => "Did not create new user/person. #{e.message}")
|
|
||||||
# return
|
|
||||||
end
|
end
|
||||||
|
params[:registration].delete :person
|
||||||
|
params[:registration].delete :user
|
||||||
|
params[:registration].delete :supporter_registration
|
||||||
|
registration.update_attributes(params[:registration])
|
||||||
|
registration.update_attributes(:conference_id => @conference.id, :attended => true)
|
||||||
|
registration.save!
|
||||||
|
redirect_to admin_conference_registrations_path(@conference.short_title)
|
||||||
|
flash[:notice] = "Successfully created new registration for #{person.email}."
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete
|
def delete
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,13 @@
|
||||||
.span12
|
.span12
|
||||||
= semantic_form_for(@registration, :url => admin_conference_registrations_new_path(@conference.short_title), :html => { :method => :put }) do |f|
|
= semantic_form_for(@registration, :url => admin_conference_registrations_new_path(@conference.short_title), :html => { :method => :put }) do |f|
|
||||||
|
|
||||||
= f.inputs "Account Information" do
|
= f.inputs "Your details" do
|
||||||
= f.fields_for :user do |u|
|
= f.fields_for :user do |u|
|
||||||
= u.input :email
|
= u.input :email, :hint => "Please enter a valid email address. You will need it to log in to OSEM later."
|
||||||
= u.input :password, :hint => "Password must be at least 6 characters"
|
= f.fields_for @person do |p|
|
||||||
= f.inputs "Personal Information" do
|
|
||||||
= f.fields_for :people do |p|
|
|
||||||
= p.input :first_name
|
= p.input :first_name
|
||||||
= p.input :last_name
|
= p.input :last_name
|
||||||
|
= p.input :public_name
|
||||||
= p.label :Nickname
|
= p.label :Nickname
|
||||||
= p.text_field :irc_nickname
|
= p.text_field :irc_nickname
|
||||||
= p.label :Affiliation
|
= p.label :Affiliation
|
||||||
|
|
@ -21,7 +20,7 @@
|
||||||
|
|
||||||
= f.inputs "Registration Information" do
|
= f.inputs "Registration Information" do
|
||||||
- if @conference.use_supporter_levels?
|
- if @conference.use_supporter_levels?
|
||||||
= f.semantic_fields_for :supporter_registrations do |reg|
|
= f.semantic_fields_for @supporter_registration do |reg|
|
||||||
= reg.input :supporter_level, :as => :select, :collection => @conference.supporter_levels
|
= reg.input :supporter_level, :as => :select, :collection => @conference.supporter_levels
|
||||||
= reg.input :code, :label => "Confirmation or registration code (if applicable)"
|
= reg.input :code, :label => "Confirmation or registration code (if applicable)"
|
||||||
%span#supporter-link.help-block
|
%span#supporter-link.help-block
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue