Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Correctly activate registration stages after omniauth/register

Oliver Günther0411b8748256
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index c6d903850ec..71890d2d28b 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -342,7 +342,7 @@ class AccountController < ApplicationController
if call.success?
flash[:notice] = call.message.presence
- login_user_if_active(call.result)
+ login_user_if_active(call.result, just_registered: true)
else
flash[:error] = error = call.message
Rails.logger.error "Registration of user #{@user.login} failed: #{error}"
@@ -413,14 +413,14 @@ class AccountController < ApplicationController
end
end
- def successful_authentication(user, reset_stages: true)
- stages = authentication_stages reset: reset_stages
+ def successful_authentication(user, reset_stages: true, just_registered: false)
+ stages = authentication_stages after_activation: just_registered, reset: reset_stages
if stages.empty?
# setting params back_url to be used by redirect_after_login
params[:back_url] = session.delete :back_url if session.include?(:back_url)
- if session[:finish_registration]
+ if session[:just_registered]
finish_registration! user
else
login_user! user
@@ -428,6 +428,7 @@ class AccountController < ApplicationController
else
stage = stages.first
+ session[:just_registered] = just_registered
session[:authenticated_user_id] = user.id
redirect_to stage.path
@@ -459,9 +460,9 @@ class AccountController < ApplicationController
cookies[OpenProject::Configuration['autologin_cookie_name']] = cookie_options
end
- def login_user_if_active(user)
+ def login_user_if_active(user, just_registered:)
if user.active?
- successful_authentication(user)
+ successful_authentication(user, just_registered: just_registered)
else
account_inactive(user, flash_now: false)
redirect_to signin_path(back_url: params[:back_url])
@@ -498,27 +499,11 @@ class AccountController < ApplicationController
render action: 'register'
end
- def run_registration_stages(stages, user, opts)
- if stages.empty?
- finish_registration! user, opts
- else
- stage = stages.first
-
- session[:authenticated_user_id] = user.id
- session[:finish_registration] = opts
-
- redirect_to stage.path
- end
- end
-
- def finish_registration!(user, opts = Hash(session.delete(:finish_registration)))
+ def finish_registration!(user)
+ session[:just_registered] = nil
self.logged_user = user
user.update last_login_on: Time.now
- if auth_hash = opts[:omni_auth_hash]
- OpenProject::OmniAuth::Authorization.after_login! user, auth_hash, self
- end
-
flash[:notice] = I18n.t(:notice_account_registered_and_logged_in)
redirect_after_login user
end
diff --git a/app/controllers/concerns/accounts/omniauth_login.rb b/app/controllers/concerns/accounts/omniauth_login.rb
index 597329d600c..ee960c6ff35 100644
--- a/app/controllers/concerns/accounts/omniauth_login.rb
+++ b/app/controllers/concerns/accounts/omniauth_login.rb
@@ -90,7 +90,7 @@ module Accounts::OmniauthLogin
if call.success?
flash[:notice] = call.message.presence
- login_user_if_active(call.result)
+ login_user_if_active(call.result, just_registered: true)
elsif call.includes_error?(:base, :failed_to_activate)
redirect_omniauth_register_modal(call.result, auth_hash)
else