Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/profiles/two_factor_auths_controller.rb')
-rw-r--r--app/controllers/profiles/two_factor_auths_controller.rb60
1 files changed, 34 insertions, 26 deletions
diff --git a/app/controllers/profiles/two_factor_auths_controller.rb b/app/controllers/profiles/two_factor_auths_controller.rb
index 0b7d4626c6d..0933f2bb7ea 100644
--- a/app/controllers/profiles/two_factor_auths_controller.rb
+++ b/app/controllers/profiles/two_factor_auths_controller.rb
@@ -15,31 +15,7 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController
feature_category :authentication_and_authorization
def show
- if two_factor_authentication_required? && !current_user.two_factor_enabled?
- two_factor_authentication_reason(
- global: lambda do
- flash.now[:alert] =
- _('The global settings require you to enable Two-Factor Authentication for your account.')
- end,
- group: lambda do |groups|
- flash.now[:alert] = groups_notification(groups)
- end
- )
-
- unless two_factor_grace_period_expired?
- grace_period_deadline = current_user.otp_grace_period_started_at + two_factor_grace_period.hours
- flash.now[:alert] = flash.now[:alert] + _(" You need to do this before %{grace_period_deadline}.") % { grace_period_deadline: l(grace_period_deadline) }
- end
- end
-
- @qr_code = build_qr_code
- @account_string = account_string
-
- if Feature.enabled?(:webauthn)
- setup_webauthn_registration
- else
- setup_u2f_registration
- end
+ setup_show_page
end
def create
@@ -147,7 +123,11 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController
current_user.increment_failed_attempts!
- redirect_to profile_two_factor_auth_path, alert: _('You must provide a valid current password')
+ @error = { message: _('You must provide a valid current password') }
+
+ setup_show_page
+
+ render 'show'
end
def current_password_required?
@@ -245,4 +225,32 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController
redirect_to profile_emails_path, notice: s_('You need to verify your primary email first before enabling Two-Factor Authentication.')
end
end
+
+ def setup_show_page
+ if two_factor_authentication_required? && !current_user.two_factor_enabled?
+ two_factor_authentication_reason(
+ global: lambda do
+ flash.now[:alert] =
+ _('The global settings require you to enable Two-Factor Authentication for your account.')
+ end,
+ group: lambda do |groups|
+ flash.now[:alert] = groups_notification(groups)
+ end
+ )
+
+ unless two_factor_grace_period_expired?
+ grace_period_deadline = current_user.otp_grace_period_started_at + two_factor_grace_period.hours
+ flash.now[:alert] = flash.now[:alert] + _(" You need to do this before %{grace_period_deadline}.") % { grace_period_deadline: l(grace_period_deadline) }
+ end
+ end
+
+ @qr_code = build_qr_code
+ @account_string = account_string
+
+ if Feature.enabled?(:webauthn)
+ setup_webauthn_registration
+ else
+ setup_u2f_registration
+ end
+ end
end