From e8bc87e62baf92757bce8b3db366df237c9122c7 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley Date: Sat, 3 Mar 2018 15:42:06 +0000 Subject: [PATCH] Ensure email validation link returns to /register paths properly --- .../authentication/login_controller.js.coffee | 6 +++--- .../services/authentication_service.js.coffee | 5 ++++- app/controllers/user_confirmations_controller.rb | 5 +++-- .../user_confirmations_controller_spec.rb | 12 +++++++++--- spec/features/consumer/authentication_spec.rb | 2 +- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/authentication/login_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/authentication/login_controller.js.coffee index 1fb3594f14..016d60d9d2 100644 --- a/app/assets/javascripts/darkswarm/controllers/authentication/login_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/authentication/login_controller.js.coffee @@ -20,8 +20,8 @@ Darkswarm.controller "LoginCtrl", ($scope, $timeout, $location, $http, $window, $scope.errors = t('devise.confirmations.failed_to_send') $timeout -> - if angular.isDefined($location.search()['confirmation']) - if $location.search()['confirmation'] == 'confirmed' + if angular.isDefined($location.search()['validation']) + if $location.search()['validation'] == 'confirmed' $scope.messages = t('devise.confirmations.confirmed') - if $location.search()['confirmation'] == 'not_confirmed' + if $location.search()['validation'] == 'not_confirmed' $scope.errors = t('devise.confirmations.not_confirmed') diff --git a/app/assets/javascripts/darkswarm/services/authentication_service.js.coffee b/app/assets/javascripts/darkswarm/services/authentication_service.js.coffee index 02543c5538..8a52f8e92b 100644 --- a/app/assets/javascripts/darkswarm/services/authentication_service.js.coffee +++ b/app/assets/javascripts/darkswarm/services/authentication_service.js.coffee @@ -7,7 +7,10 @@ Darkswarm.factory "AuthenticationService", (Navigation, $modal, $location, Redir if $location.path() in ["/login", "/signup", "/forgot"] && location.pathname isnt '/register/auth' @open $location.path() else if location.pathname is '/register/auth' - @open '/signup', 'registration_authentication.html' + if angular.isDefined($location.search()['validation']) + @open '/login', 'registration_authentication.html' + else + @open '/signup', 'registration_authentication.html' open: (path = false, template = 'authentication.html') => @modalInstance = $modal.open diff --git a/app/controllers/user_confirmations_controller.rb b/app/controllers/user_confirmations_controller.rb index 20046657c5..f5ee6a10e5 100644 --- a/app/controllers/user_confirmations_controller.rb +++ b/app/controllers/user_confirmations_controller.rb @@ -38,7 +38,8 @@ class UserConfirmationsController < DeviseController 'not_confirmed' end - url = session[:confirmation_return_url] || login_path - url + "?confirmation=#{result}" + path = (session[:confirmation_return_url] || login_path).to_s + path += path.include?('?') ? '&' : '?' + path + "validation=#{result}" end end diff --git a/spec/controllers/user_confirmations_controller_spec.rb b/spec/controllers/user_confirmations_controller_spec.rb index 6b1e15fc4b..d264a011a0 100644 --- a/spec/controllers/user_confirmations_controller_spec.rb +++ b/spec/controllers/user_confirmations_controller_spec.rb @@ -20,14 +20,14 @@ describe UserConfirmationsController, type: :controller do end it "redirects the user to login" do - expect(response).to redirect_to login_path(confirmation: 'not_confirmed') + expect(response).to redirect_to login_path(validation: 'not_confirmed') end end context "that has not been confirmed" do it "redirects the user to login" do spree_get :show, confirmation_token: unconfirmed_user.confirmation_token - expect(response).to redirect_to login_path(confirmation: 'confirmed') + expect(response).to redirect_to login_path(validation: 'confirmed') end it "confirms the user" do @@ -38,7 +38,13 @@ describe UserConfirmationsController, type: :controller do it "redirects to previous url" do session[:confirmation_return_url] = producers_path + '#/login' spree_get :show, confirmation_token: unconfirmed_user.confirmation_token - expect(response).to redirect_to producers_path + '#/login?confirmation=confirmed' + expect(response).to redirect_to producers_path + '#/login?validation=confirmed' + end + + it "redirects to previous url on /register path" do + session[:confirmation_return_url] = registration_path + '#/signup?after_login=%2Fregister' + spree_get :show, confirmation_token: unconfirmed_user.confirmation_token + expect(response).to redirect_to registration_path + '#/signup?after_login=%2Fregister&validation=confirmed' end end end diff --git a/spec/features/consumer/authentication_spec.rb b/spec/features/consumer/authentication_spec.rb index b8d42a5a82..b1f8b1be1f 100644 --- a/spec/features/consumer/authentication_spec.rb +++ b/spec/features/consumer/authentication_spec.rb @@ -124,7 +124,7 @@ feature "Authentication", js: true, retry: 3 do describe "after following email confirmation link" do scenario "shows confirmed message in modal" do - visit '/#/login?confirmation=confirmed' + visit '/#/login?validation=confirmed' expect(page).to have_login_modal expect(page).to have_content I18n.t('devise.confirmations.confirmed') end