Implements sign up during registration. Solves most of #215
This commit is contained in:
parent
511007138a
commit
e8ab94e1c7
12 changed files with 101 additions and 36 deletions
|
|
@ -68,3 +68,7 @@ p.comment-body {
|
||||||
.well.comment-section {
|
.well.comment-section {
|
||||||
padding-bottom: 40px;
|
padding-bottom: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#account-already {
|
||||||
|
font-size: 0.6em;
|
||||||
|
}
|
||||||
|
|
@ -43,7 +43,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue_from CanCan::AccessDenied do |exception|
|
rescue_from CanCan::AccessDenied do |exception|
|
||||||
Rails.logger.debug('Access denied!')
|
Rails.logger.debug "Access denied on #{exception.action} #{exception.subject.inspect}"
|
||||||
redirect_to root_path, alert: exception.message
|
redirect_to root_path, alert: exception.message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,16 @@
|
||||||
class ConferenceRegistrationsController < ApplicationController
|
class ConferenceRegistrationsController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!, except: [:new, :create]
|
||||||
load_resource :conference, find_by: :short_title
|
load_resource :conference, find_by: :short_title
|
||||||
authorize_resource :conference_registrations, class: Registration
|
authorize_resource :conference_registrations, class: Registration
|
||||||
before_action :set_registration, only: [:edit, :update, :destroy, :show]
|
before_action :set_registration, only: [:edit, :update, :destroy, :show]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@registration = current_user.registrations.build(conference_id: @conference.id)
|
# ichain does not allow us to create users during registration
|
||||||
|
if CONFIG['authentication']['ichain']['enabled'] && !current_user
|
||||||
|
redirect_to root_path, alert: 'You need to sign in or sign up before continuing.'
|
||||||
|
end
|
||||||
|
@registration = Registration.new
|
||||||
|
@registration.build_user
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|
@ -17,19 +22,24 @@ class ConferenceRegistrationsController < ApplicationController
|
||||||
def edit; end
|
def edit; end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@registration = current_user.registrations.build(registration_params)
|
@registration = Registration.new(registration_params)
|
||||||
@registration.conference_id = @conference.id
|
@registration.conference = @conference
|
||||||
|
@registration.user = current_user if current_user
|
||||||
|
|
||||||
if @registration.save
|
if @registration.save
|
||||||
# Trigger ahoy event
|
# Trigger ahoy event
|
||||||
ahoy.track 'Registered', title: 'New registration'
|
ahoy.track 'Registered', title: 'New registration'
|
||||||
|
|
||||||
|
# Sign in the new user
|
||||||
|
if !current_user
|
||||||
|
sign_in(@registration.user)
|
||||||
|
end
|
||||||
|
|
||||||
|
flash[:notice] = 'You are now registered and will be receiving E-Mail notifications.'
|
||||||
if @conference.tickets.any? && !current_user.supports?(@conference)
|
if @conference.tickets.any? && !current_user.supports?(@conference)
|
||||||
redirect_to conference_tickets_path(@conference.short_title),
|
redirect_to conference_tickets_path(@conference.short_title)
|
||||||
notice: 'You are now registered and will be receiving E-Mail notifications.'
|
|
||||||
else
|
else
|
||||||
redirect_to conference_conference_registrations_path(@conference.short_title),
|
redirect_to conference_conference_registrations_path(@conference.short_title)
|
||||||
notice: 'You are now registered and will be receiving E-Mail notifications.'
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
flash[:error] = "An error prohibited the registration for #{@conference.title}: "\
|
flash[:error] = "An error prohibited the registration for #{@conference.title}: "\
|
||||||
|
|
@ -63,8 +73,9 @@ class ConferenceRegistrationsController < ApplicationController
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def set_registration
|
def set_registration
|
||||||
@registration = current_user.registrations.find_by(conference_id: @conference.id)
|
@registration = Registration.find_by(conference: @conference, user: current_user)
|
||||||
if !@registration
|
if !@registration
|
||||||
|
flash[:alert] = "Can't find a registration for #{@conference.title} for you. Please register."
|
||||||
redirect_to new_conference_conference_registrations_path(@conference.short_title)
|
redirect_to new_conference_conference_registrations_path(@conference.short_title)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -78,7 +89,7 @@ class ConferenceRegistrationsController < ApplicationController
|
||||||
qanswers_attributes: [],
|
qanswers_attributes: [],
|
||||||
event_ids: [],
|
event_ids: [],
|
||||||
user_attributes: [
|
user_attributes: [
|
||||||
:id, :name, :tshirt, :mobile, :volunteer_experience, :languages]
|
:username, :email, :name, :password, :password_confirmation]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,8 @@ module Users
|
||||||
openid.save!
|
openid.save!
|
||||||
|
|
||||||
sign_in user
|
sign_in user
|
||||||
redirect_to root_path, notice: user.email + " signed in successfully with #{provider}"
|
flash[:notice] = "#{user.email} signed in successfully with #{provider}"
|
||||||
|
redirect_to request.env['omniauth.origin'] || root_path
|
||||||
rescue => e
|
rescue => e
|
||||||
flash[:error] = e.message
|
flash[:error] = e.message
|
||||||
redirect_back_or_to new_user_registration_path
|
redirect_back_or_to new_user_registration_path
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def bootstrap_class_for(flash_type)
|
def bootstrap_class_for(flash_type)
|
||||||
logger.debug "flash_type is #{flash_type}"
|
|
||||||
case flash_type
|
case flash_type
|
||||||
when 'success'
|
when 'success'
|
||||||
'alert-success'
|
'alert-success'
|
||||||
|
|
@ -35,7 +34,7 @@ module ApplicationHelper
|
||||||
when 'notice'
|
when 'notice'
|
||||||
'alert-info'
|
'alert-info'
|
||||||
else
|
else
|
||||||
flash_type.to_s
|
'alert-warning'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,10 @@ class Ability
|
||||||
can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id)
|
can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id)
|
||||||
# can view others
|
# can view others
|
||||||
can :show, User
|
can :show, User
|
||||||
|
# can register
|
||||||
|
can [:show, :create], Registration do |registration|
|
||||||
|
registration.new_record?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def signed_in(user)
|
def signed_in(user)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
class Registration < ActiveRecord::Base
|
class Registration < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
validates :user, presence: true
|
||||||
|
accepts_nested_attributes_for :user
|
||||||
belongs_to :conference
|
belongs_to :conference
|
||||||
belongs_to :dietary_choice
|
belongs_to :dietary_choice
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,62 @@
|
||||||
Registration for
|
Registration for
|
||||||
= @conference.title
|
= @conference.title
|
||||||
.row
|
.row
|
||||||
.col-md-8
|
.col-md-6
|
||||||
= semantic_form_for(@registration, url: conference_conference_registrations_path(@conference.short_title)) do |f|
|
- if !current_user
|
||||||
- if @conference.questions.any?
|
%legend
|
||||||
= render partial: 'questions', locals: { f: f }
|
%span
|
||||||
- if @conference.events.workshops.any?
|
=link_to('#signup', role: 'tab', "aria-controls" => "home", "data-toggle" => "tab") do
|
||||||
=f.inputs 'Register to Workshops' do
|
= CONFIG['name']
|
||||||
= f.input :events, as: :check_boxes, label: false, collection: @conference.events.workshops
|
Account
|
||||||
= f.inputs 'Your Travel Info' do
|
%span.pull-right#account-already
|
||||||
= f.input :arrival, as: :string, label: 'Your arrival time', input_html: { value: (f.object.arrival.to_formatted_s(:db_without_seconds) unless f.object.arrival.nil?), id: 'registration-arrival-datepicker', readonly: 'readonly' }
|
=link_to('#signin', role: 'tab', "aria-controls" => "home", "data-toggle" => "tab") do
|
||||||
= f.input :departure, as: :string, label: 'Your departure time', input_html: { value: (f.object.departure.to_formatted_s(:db_without_seconds) unless f.object.departure.nil?), id: 'registration-departure-datepicker', readonly: 'readonly' }
|
Already have an account?
|
||||||
%p.pull-right
|
.tab-content
|
||||||
- if @conference.user_registered?(current_user)
|
.tab-pane.active{role: 'tabpanel', id: 'signup'}
|
||||||
= f.action :submit, button_html: { value: 'Update Registration', class: 'btn btn-primary' }
|
= semantic_form_for(@registration, url: conference_conference_registrations_path(@conference.short_title)) do |f|
|
||||||
- else
|
- if !current_user
|
||||||
= f.action :submit, button_html: { value: 'Register', class: 'btn btn-primary', id: 'register' }
|
= f.fields_for :user do |u|
|
||||||
|
= u.input :username, input_html: {required: 'required', autocomplete: 'off'}
|
||||||
|
= u.input :email, input_html: {required: 'required', autocomplete: 'off'}
|
||||||
|
= u.input :password, input_html: {required: 'required', autocomplete: 'off'}
|
||||||
|
= u.input :password_confirmation, :required => true, input_html: {required: 'required', autocomplete: 'off'}
|
||||||
|
- if @conference.questions.any?
|
||||||
|
= render partial: 'questions', locals: { f: f }
|
||||||
|
- if @conference.events.workshops.any?
|
||||||
|
=f.inputs 'Register to Workshops' do
|
||||||
|
= f.input :events, as: :check_boxes, label: false, collection: @conference.events.workshops
|
||||||
|
= f.inputs 'Your Travel Info' do
|
||||||
|
= f.input :arrival, as: :string, label: 'Your arrival time', input_html: { value: (f.object.arrival.to_formatted_s(:db_without_seconds) unless f.object.arrival.nil?), id: 'registration-arrival-datepicker', readonly: 'readonly' }
|
||||||
|
= f.input :departure, as: :string, label: 'Your departure time', input_html: { value: (f.object.departure.to_formatted_s(:db_without_seconds) unless f.object.departure.nil?), id: 'registration-departure-datepicker', readonly: 'readonly' }
|
||||||
|
%p.pull-right
|
||||||
|
- if @conference.user_registered?(current_user)
|
||||||
|
= f.action :submit, button_html: { value: 'Update Registration', class: 'btn btn-primary' }
|
||||||
|
- else
|
||||||
|
= f.action :submit, button_html: { value: 'Register', class: 'btn btn-primary', id: 'register' }
|
||||||
|
.tab-pane{role: 'tabpanel', id: 'signin'}
|
||||||
|
- if !CONFIG['authentication']['ichain']['enabled']
|
||||||
|
= form_tag(new_user_session_path, class: 'form-horizontal') do
|
||||||
|
%legend
|
||||||
|
%span
|
||||||
|
Sign In
|
||||||
|
.form-group
|
||||||
|
%label{for: "user[login]", class: 'col-sm-2 control-label'}
|
||||||
|
Username
|
||||||
|
.col-sm-10
|
||||||
|
= text_field_tag 'user[login]', nil, placeholder: 'Username', class: 'form-control', required: 'required'
|
||||||
|
.form-group
|
||||||
|
%label{for: "user[password]", class: 'col-sm-2 control-label'}
|
||||||
|
Password
|
||||||
|
.col-sm-10
|
||||||
|
= password_field_tag 'user[password]', nil, placeholder: 'Password', class: 'form-control', required: 'required'
|
||||||
|
.form-group
|
||||||
|
.col-sm-12
|
||||||
|
%button.btn.btn-success.pull-right
|
||||||
|
Sign in
|
||||||
|
- unless omniauth_configured.empty?
|
||||||
|
.form-group
|
||||||
|
%hr
|
||||||
|
%p.text-center
|
||||||
|
or sign in using
|
||||||
|
.text-center
|
||||||
|
= render 'devise/shared/openid'
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
- @conference.questions.each do |q|
|
= f.inputs 'Additional Info' do
|
||||||
= f.inputs 'Additional Info' do
|
- @conference.questions.each do |q|
|
||||||
- if q.question_type.id == 1 || q.question_type.id == 2 # yes/no or single choice
|
- if q.question_type.id == 1 || q.question_type.id == 2 # yes/no or single choice
|
||||||
= f.input :qanswers, :collection => q.qanswers, :as => :select, :input_html => { :multiple => false, class: 'col-sm-10' }, label: q.title, :include_blank => "Please make your choice",
|
= f.input :qanswers, :collection => q.qanswers, :as => :select, :input_html => { :multiple => false }, label: q.title, :include_blank => "Please make your choice",
|
||||||
:member_label => Proc.new {|a| a.answer.title}
|
:member_label => Proc.new {|a| a.answer.title}
|
||||||
- if q.question_type.id == 3 # multiple choice
|
- if q.question_type.id == 3 # multiple choice
|
||||||
= f.input :qanswers, :collection => q.qanswers, :as => :check_boxes, :input_html => { class: 'col-sm-2' }, :label => false,
|
= f.input :qanswers, :collection => q.qanswers, :as => :check_boxes, label: q.title,
|
||||||
:member_label => Proc.new {|a| a.answer.title}
|
:member_label => Proc.new {|a| a.answer.title}
|
||||||
|
|
@ -105,7 +105,7 @@ Devise.setup do |config|
|
||||||
# able to access the website for two days without confirming his account,
|
# able to access the website for two days without confirming his account,
|
||||||
# access will be blocked just in the third day. Default is 0.days, meaning
|
# access will be blocked just in the third day. Default is 0.days, meaning
|
||||||
# the user cannot access the website without confirming his account.
|
# the user cannot access the website without confirming his account.
|
||||||
# config.allow_unconfirmed_access_for = 2.days
|
config.allow_unconfirmed_access_for = 2.days
|
||||||
|
|
||||||
# If true, requires any email changes to be confirmed (exactly the same way as
|
# If true, requires any email changes to be confirmed (exactly the same way as
|
||||||
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ Formtastic::FormBuilder.include_blank_for_select_by_default = false
|
||||||
# '<abbr title="required">*</abbr>'. In other words, if you configure formtastic.required
|
# '<abbr title="required">*</abbr>'. In other words, if you configure formtastic.required
|
||||||
# in your locale, it will replace the abbr title properly. But if you don't want to use
|
# in your locale, it will replace the abbr title properly. But if you don't want to use
|
||||||
# abbr tag, you can simply give a string as below
|
# abbr tag, you can simply give a string as below
|
||||||
Formtastic::FormBuilder.required_string = '(required)'
|
Formtastic::FormBuilder.required_string = proc { Formtastic::Util.html_safe(%{ <span class="text-warning"><abbr title="This field is required">*</abbr></span>}) }
|
||||||
|
|
||||||
# Set the string that will be appended to the labels/fieldsets which are optional
|
# Set the string that will be appended to the labels/fieldsets which are optional
|
||||||
# Defaults to an empty string ("") and also accepts procs (see required_string above)
|
# Defaults to an empty string ("") and also accepts procs (see required_string above)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20141130182139) do
|
ActiveRecord::Schema.define(version: 20150304135935) do
|
||||||
|
|
||||||
create_table "ahoy_events", force: true do |t|
|
create_table "ahoy_events", force: true do |t|
|
||||||
t.uuid "visit_id"
|
t.uuid "visit_id"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue