A platform for community discussion. Free, open, simple.
FIX: Clear authentication data from session after create account (#8040)
David Taylor73172f00d3e1
diff --git a/app/services/user_authenticator.rb b/app/services/user_authenticator.rbindex c2361f6a5d1..d988300ceb8 100644--- a/app/services/user_authenticator.rb+++ b/app/services/user_authenticator.rb@@ -4,7 +4,8 @@ class UserAuthenticatordef initialize(user, session, authenticator_finder = Users::OmniauthCallbacksController)@user = user- @session = session[:authentication]+ @session = session+ @auth_session = session[:authentication]@authenticator_finder = authenticator_finderend@@ -15,7 +16,7 @@ class UserAuthenticator@user.password_required!end- @user.skip_email_validation = true if @session && @session[:skip_email_validation].present?+ @user.skip_email_validation = true if @auth_session && @auth_session[:skip_email_validation].present?enddef has_authenticator?@@ -24,18 +25,18 @@ class UserAuthenticatordef finishif authenticator- authenticator.after_create_account(@user, @session)+ authenticator.after_create_account(@user, @auth_session)confirm_emailend- @session = nil+ @session[:authentication] = @auth_session = nil if @auth_sessionenddef email_valid?- @session && @session[:email_valid]+ @auth_session && @auth_session[:email_valid]enddef authenticated?- @session && @session[:email]&.downcase == @user.email.downcase && @session[:email_valid].to_s == "true"+ @auth_session && @auth_session[:email]&.downcase == @user.email.downcase && @auth_session[:email_valid].to_s == "true"endprivate@@ -54,7 +55,7 @@ class UserAuthenticatorenddef authenticator_name- @session && @session[:authenticator_name]+ @auth_session && @auth_session[:authenticator_name]endenddiff --git a/spec/services/user_authenticator_spec.rb b/spec/services/user_authenticator_spec.rbindex b54f282f153..7ee4543d147 100644--- a/spec/services/user_authenticator_spec.rb+++ b/spec/services/user_authenticator_spec.rb@@ -57,5 +57,15 @@ describe UserAuthenticator doexpect(user.email_confirmed?).to be_falseyexpect(group.usernames).not_to include(user.username)end++ it "clears the authentication info from the session" do+ user = Fabricate(:user, email: "[email protected]")+ session = { authentication: github_auth(true) }++ UserAuthenticator.new(user, session).finish+ expect(user.email_confirmed?).to be_truthy++ expect(session[:authentication]).to eq(nil)+ endendend