diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 42419769..1bb1ced5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -34,7 +34,7 @@ class ApplicationController < ActionController::Base :authenticate_user! if (current_user.nil?) - redirect_to new_user_session_path + redirect_to new_user_registration_path return false end diff --git a/app/controllers/confirmations_controller.rb b/app/controllers/confirmations_controller.rb new file mode 100644 index 00000000..2a4757ce --- /dev/null +++ b/app/controllers/confirmations_controller.rb @@ -0,0 +1,40 @@ +class ConfirmationsController < Devise::ConfirmationsController + def show + self.resource = resource_class.confirm_by_token(params[:confirmation_token]) + yield resource if block_given? + + if Conference.all.count == 1 && Conference.first.registration_open? + @conference = Conference.first + @conference.registrations.create!(user_id: self.resource.id) + @redirection_path = register_conference_path(@conference.short_title) + end + + sign_in resource if resource + + if resource.errors.empty? + if @redirection_path.blank? + set_flash_message(:notice, :confirmed) if is_flashing_format? + else + set_flash_message(:notice, :confirmed_registered) if is_flashing_format? + end + respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) } and return + else + respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new } and return + end + end + + private + + def after_confirmation_path_for(resource_name, resource) + + if @redirection_path.blank? + if signed_in? + signed_in_root_path(resource) + else + new_session_path(resource_name) + end + else + @redirection_path + end + end +end diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml index 18e044e2..e3ad2ab3 100644 --- a/config/locales/devise.en.yml +++ b/config/locales/devise.en.yml @@ -34,6 +34,7 @@ en: send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.' send_paranoid_instructions: 'If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes.' confirmed: 'Your account was successfully confirmed. NOTE: You have not been automatically registered to attend a conference!' + confirmed_registered: 'Your account was successfully confirmed and you have been automatically registered to attend the conference. You can update or cancel your registration below.' registrations: signed_up: 'Welcome! You have signed up successfully.' signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.' diff --git a/config/routes.rb b/config/routes.rb index 41cd31e8..3580f25c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,7 @@ Osem::Application.routes.draw do get 'conference/show' - devise_for :users, controllers: { registrations: :registrations, + devise_for :users, controllers: { registrations: :registrations, confirmations: :confirmations, omniauth_callbacks: 'users/omniauth_callbacks' }, path: 'accounts' diff --git a/spec/controllers/admin/conferences_controller_spec.rb b/spec/controllers/admin/conferences_controller_spec.rb index 961f6463..ddb1d447 100644 --- a/spec/controllers/admin/conferences_controller_spec.rb +++ b/spec/controllers/admin/conferences_controller_spec.rb @@ -261,7 +261,7 @@ describe Admin::ConferenceController do describe 'guest access' do - it_behaves_like 'access as participant or guest', :new_user_session_path + it_behaves_like 'access as participant or guest', :new_user_registration_path end end