diff --git a/app/controllers/auth_controller.rb b/app/controllers/auth_controller.rb new file mode 100644 index 000000000..995015287 --- /dev/null +++ b/app/controllers/auth_controller.rb @@ -0,0 +1,14 @@ +class AuthController < ApplicationController + def callback + # We come here after one login + # We will need to restore, form_id, mode and form_slug, which we should have saved before sending + if session["return_to"].present? + + # We need to do something to get the user's email here. + # + # We then need to set the email in the session somewhere + session["one_login_email"] = "example@example.org" + redirect_to session["return_to"] + end + end +end diff --git a/app/controllers/fake_onelogin_controller.rb b/app/controllers/fake_onelogin_controller.rb new file mode 100644 index 000000000..0972d92c5 --- /dev/null +++ b/app/controllers/fake_onelogin_controller.rb @@ -0,0 +1,8 @@ +class FakeOneloginController < ApplicationController + def show + end + + def create + redirect_to auth_callback_path(mode: "preview-draft", form_id: 14, form_slug: "testing-none-of-the-above") + end +end diff --git a/app/controllers/forms/check_your_answers_controller.rb b/app/controllers/forms/check_your_answers_controller.rb index e81cc2843..746687a6a 100644 --- a/app/controllers/forms/check_your_answers_controller.rb +++ b/app/controllers/forms/check_your_answers_controller.rb @@ -36,6 +36,14 @@ def submit_answers return render template: "errors/incomplete_submission", locals: { form: @form, current_context: } end + if email_confirmation_input.send_confirmation == "onelogin" + # TODO: We need to save where to comeback to here in a cookie or session state + # When we come back from one login, we'll need mode, form_id and form_slug? + session["return_to"] = request.fullpath + return redirect_to onelogin_path + # return redirect_to auth_url + end + begin submission_reference = FormSubmissionService.call(current_context:, email_confirmation_input:, @@ -55,6 +63,37 @@ def submit_answers render "errors/submission_error", status: :internal_server_error end + # TODO: This is a new method, which will handle the submission for the one login callback + def auth_callback + return redirect_to error_repeat_submission_path(@form.id) if current_context.form_submitted? + + unless current_context.can_visit?(CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG) + EventLogger.log_form_event("incomplete_or_repeat_submission_error") + return render template: "errors/incomplete_submission", locals: { form: @form, current_context: } + end + + begin + # Let's hackily build an email_confirmation_input mocked up with the email. + # This will send the current confirmation email to the one login address, which isn't what we want eventally + # but might be handy to test it + confirmation_email_address = session["one_login_email"] + email_confirmation_input = EmailConfirmationInput.new(confirmation_email_address:, send_confirmation: :send_email) + requested_email_confirmation = email_confirmation_input.send_confirmation == "send_email" + submission_reference = FormSubmissionService.call(current_context:, + email_confirmation_input:, + mode:).submit + + current_context.save_submission_details(submission_reference, requested_email_confirmation) + session["one_login_email"] = nil + + redirect_to :form_submitted + rescue StandardError => e + log_rescued_exception(e) + + render "errors/submission_error", status: :internal_server_error + end + end + private def email_confirmation_input_params diff --git a/app/input_objects/email_confirmation_input.rb b/app/input_objects/email_confirmation_input.rb index aceb8920f..cac01e089 100644 --- a/app/input_objects/email_confirmation_input.rb +++ b/app/input_objects/email_confirmation_input.rb @@ -8,7 +8,7 @@ class EmailConfirmationInput before_validation :strip_email_whitespace validates :send_confirmation, presence: true - validates :send_confirmation, inclusion: { in: %w[send_email skip_confirmation] } + validates :send_confirmation, inclusion: { in: %w[send_email skip_confirmation onelogin] } validates :confirmation_email_address, presence: true, if: :validate_email? validates :confirmation_email_address, email_address: { message: :invalid_email }, allow_blank: true, if: :validate_email? diff --git a/app/views/fake_onelogin/show.html.erb b/app/views/fake_onelogin/show.html.erb new file mode 100644 index 000000000..068d24a7a --- /dev/null +++ b/app/views/fake_onelogin/show.html.erb @@ -0,0 +1,9 @@ +