diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 683ff321d..015fd30a2 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -33,6 +33,9 @@ class DashboardController < ApplicationController klass = user.unconfirmed_email? ? Users::Reverify : Users::Verify @token = klass.run!(user: user).to_json render :confirmation_page, layout: false + rescue User::AlreadyVerified + @already_registered = true + render :confirmation_page, layout: false, status: 409 end # Endpoint reports CSP violations, indicating a possible security problem. diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 061ccb54f..128aff801 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -28,6 +28,8 @@ class UserMailer < ApplicationMailer end def self.reset_url(user) - RESET_PATH % [$API_URL, user.confirmation_token] + x = URI(RESET_PATH % [$API_URL, user.confirmation_token]) + (x.port = nil) if (x.port === 443) # Sendgrid does not like :443 in URLs. + x.to_s end end diff --git a/app/views/dashboard/confirmation_page.html.erb b/app/views/dashboard/confirmation_page.html.erb index 248f989d7..4c1957bd1 100644 --- a/app/views/dashboard/confirmation_page.html.erb +++ b/app/views/dashboard/confirmation_page.html.erb @@ -1,9 +1,14 @@ - You are being <%= link_to "redirected", app_landing_page_path %>. - + <% if @already_registered %> + You have already verified your account. + Please <%= link_to "log in", "/" %>. + <% else %> +

You are now being <%= link_to "redirected", app_landing_page_path %>.

+ + <% end %> diff --git a/spec/controllers/api/users/verification_spec.rb b/spec/controllers/api/users/verification_spec.rb deleted file mode 100644 index e69de29bb..000000000 diff --git a/spec/controllers/dashboarad_failures_spec.rb b/spec/controllers/dashboarad_failures_spec.rb new file mode 100644 index 000000000..a62e6614c --- /dev/null +++ b/spec/controllers/dashboarad_failures_spec.rb @@ -0,0 +1,13 @@ +describe DashboardController do + include Devise::Test::ControllerHelpers + let(:user) { FactoryBot.create(:user, confirmed_at: nil) } + render_views + + it 'can not re-verify' do + user.update_attributes(confirmed_at: Time.now) + sign_in user + get :verify, params: { token: user.confirmation_token } + expect(response.status).to eq(409) + expect(response.body).to include("already verified") + end +end diff --git a/spec/controllers/dashboard_spec.rb b/spec/controllers/dashboard_spec.rb index 4325abf16..8acc0738b 100644 --- a/spec/controllers/dashboard_spec.rb +++ b/spec/controllers/dashboard_spec.rb @@ -50,14 +50,5 @@ describe DashboardController do expect(user.reload.unconfirmed_email).to be nil expect(user.email).to eq email end - - it 'can not re-verify' do - user.update_attributes(confirmed_at: Time.now) - sign_in user - expect do - get :verify, params: { token: user.confirmation_token }, format: :json - end.to raise_error(User::AlreadyVerified) - # expect(response.status).to eq(409) - end end end