diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-13 15:09:32 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-13 15:09:32 +0000 |
commit | bd25f1d9c685039381df23e49bc52cdcf4ec1b4a (patch) | |
tree | 33b3b16ae2ef653f74828f69742154122ff0ac2d /app/controllers/profiles | |
parent | 70ce746bd011b101605e6d84f141d1f0c3175831 (diff) | |
download | gitlab-ce-bd25f1d9c685039381df23e49bc52cdcf4ec1b4a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/controllers/profiles')
-rw-r--r-- | app/controllers/profiles/two_factor_auths_controller.rb | 60 |
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 |