From 12a8fbddb5db715114f28f8fac9fb5238d5bc562 Mon Sep 17 00:00:00 2001 From: Michael Kohl Date: Thu, 28 Jan 2021 09:32:04 +0700 Subject: [PATCH] Add flash message for email confirmation (#12450) * Add flash message for email confirmation * Fix spec --- app/controllers/confirmations_controller.rb | 13 +++++++++++++ config/routes.rb | 5 +++-- .../user_request_confirmation_spec.rb | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 app/controllers/confirmations_controller.rb create mode 100644 spec/system/authentication/user_request_confirmation_spec.rb diff --git a/app/controllers/confirmations_controller.rb b/app/controllers/confirmations_controller.rb new file mode 100644 index 000000000..cfda9e7f1 --- /dev/null +++ b/app/controllers/confirmations_controller.rb @@ -0,0 +1,13 @@ +class ConfirmationsController < Devise::ConfirmationsController + FLASH_MESSAGE = "Email sent! Please contact support at %s if you are "\ + "having trouble receiving your confirmation instructions.".freeze + + def create + self.resource = resource_class.send_confirmation_instructions(resource_params) + resource.errors.clear # Don't leak user information, like paranoid mode. + + message = format(FLASH_MESSAGE, email: SiteConfig.email_addresses[:members]) + flash.now[:global_notice] = message + render :new + end +end diff --git a/config/routes.rb b/config/routes.rb index 07ea51c2d..e4730c667 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,12 +11,13 @@ Rails.application.routes.draw do omniauth_callbacks: "omniauth_callbacks", registrations: "registrations", invitations: "invitations", - passwords: "passwords" + passwords: "passwords", + confirmations: "confirmations" } devise_scope :user do get "/enter", to: "registrations#new", as: :sign_up - get "/confirm-email", to: "devise/confirmations#new" + get "/confirm-email", to: "confirmations#new" delete "/sign_out", to: "devise/sessions#destroy" end diff --git a/spec/system/authentication/user_request_confirmation_spec.rb b/spec/system/authentication/user_request_confirmation_spec.rb new file mode 100644 index 000000000..3333b6e1f --- /dev/null +++ b/spec/system/authentication/user_request_confirmation_spec.rb @@ -0,0 +1,14 @@ +require "rails_helper" + +RSpec.describe "/confirm-email", type: :system do + it "stays on the same page and displays a flash message", :aggregate_failures do + visit confirm_email_path + fill_in "user_email", with: "test@example.com" + click_button "Resend confirmation instructions" + + expect(page).to have_current_path(user_confirmation_path) + expected_message = format(ConfirmationsController::FLASH_MESSAGE, + email: SiteConfig.email_addresses[:members]) + expect(page).to have_content(expected_message) + end +end