Merge pull request #615 from hennevogel/master

Implements sign up during registration. Solves most of #215
This commit is contained in:
Henne Vogelsang 2015-03-26 14:30:14 +01:00
commit defef46ae8
14 changed files with 113 additions and 117 deletions

View file

@ -68,3 +68,7 @@ p.comment-body {
.well.comment-section {
padding-bottom: 40px;
}
#account-already {
font-size: 0.6em;
}

View file

@ -1,7 +1,7 @@
module Admin
class RegistrationsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference
load_and_authorize_resource :registration, through: :conference
before_filter :set_user, except: [:index]
def index

View file

@ -43,7 +43,7 @@ class ApplicationController < ActionController::Base
end
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
end

View file

@ -1,11 +1,16 @@
class ConferenceRegistrationsController < ApplicationController
before_filter :authenticate_user!
before_filter :authenticate_user!, except: [:new, :create]
load_resource :conference, find_by: :short_title
authorize_resource :conference_registrations, class: Registration
before_action :set_registration, only: [:edit, :update, :destroy, :show]
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
def show
@ -17,19 +22,24 @@ class ConferenceRegistrationsController < ApplicationController
def edit; end
def create
@registration = current_user.registrations.build(registration_params)
@registration.conference_id = @conference.id
@registration = Registration.new(registration_params)
@registration.conference = @conference
@registration.user = current_user if current_user
if @registration.save
# Trigger ahoy event
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)
redirect_to conference_tickets_path(@conference.short_title),
notice: 'You are now registered and will be receiving E-Mail notifications.'
redirect_to conference_tickets_path(@conference.short_title)
else
redirect_to conference_conference_registrations_path(@conference.short_title),
notice: 'You are now registered and will be receiving E-Mail notifications.'
redirect_to conference_conference_registrations_path(@conference.short_title)
end
else
flash[:error] = "An error prohibited the registration for #{@conference.title}: "\
@ -63,8 +73,9 @@ class ConferenceRegistrationsController < ApplicationController
protected
def set_registration
@registration = current_user.registrations.find_by(conference_id: @conference.id)
@registration = Registration.find_by(conference: @conference, user: current_user)
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)
end
end
@ -78,7 +89,7 @@ class ConferenceRegistrationsController < ApplicationController
qanswers_attributes: [],
event_ids: [],
user_attributes: [
:id, :name, :tshirt, :mobile, :volunteer_experience, :languages]
:username, :email, :name, :password, :password_confirmation]
)
end
end

View file

@ -28,7 +28,8 @@ module Users
openid.save!
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
flash[:error] = e.message
redirect_back_or_to new_user_registration_path

View file

@ -24,7 +24,6 @@ module ApplicationHelper
end
def bootstrap_class_for(flash_type)
logger.debug "flash_type is #{flash_type}"
case flash_type
when 'success'
'alert-success'
@ -35,7 +34,7 @@ module ApplicationHelper
when 'notice'
'alert-info'
else
flash_type.to_s
'alert-warning'
end
end

View file

@ -121,6 +121,10 @@ class Ability
can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id)
# can view others
can :show, User
# can register
can [:read, :create], Registration do |registration|
registration.new_record?
end
end
def signed_in(user)

View file

@ -1,5 +1,7 @@
class Registration < ActiveRecord::Base
belongs_to :user
validates :user, presence: true
accepts_nested_attributes_for :user
belongs_to :conference
belongs_to :dietary_choice

View file

@ -6,18 +6,62 @@
Registration for
= @conference.title
.row
.col-md-8
= semantic_form_for(@registration, url: conference_conference_registrations_path(@conference.short_title)) do |f|
- 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' }
.col-md-6
- if !current_user
%legend
%span
=link_to('#signup', role: 'tab', "aria-controls" => "home", "data-toggle" => "tab") do
= CONFIG['name']
Account
%span.pull-right#account-already
=link_to('#signin', role: 'tab', "aria-controls" => "home", "data-toggle" => "tab") do
Already have an account?
.tab-content
.tab-pane.active{role: 'tabpanel', id: 'signup'}
= semantic_form_for(@registration, url: conference_conference_registrations_path(@conference.short_title)) do |f|
- if !current_user
= 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'

View file

@ -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
= 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}
- 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}