Merge pull request #3561 from aignatov-bio/ai-sci-6103-fix-2fa-redirecting

Fix 2fa redirecting [SCI-6103]
This commit is contained in:
Alex Kriuchykhin 2021-09-29 15:15:17 +02:00 committed by GitHub
commit 79074114f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View file

@ -23,9 +23,10 @@ class Users::SessionsController < Devise::SessionsController
def create
super do |user|
if redirect_to_two_factor_auth?(user)
initial_page = stored_location_for(:user)
sign_out
session[:otp_user_id] = user.id
store_location_for(:user, request.original_fullpath) if request.get?
store_location_for(:user, initial_page)
redirect_to users_two_factor_auth_path
return
end
@ -40,6 +41,7 @@ class Users::SessionsController < Devise::SessionsController
end
def two_factor_auth
@initial_page = stored_location_for(:user)
end
def after_sign_in
@ -60,7 +62,7 @@ class Users::SessionsController < Devise::SessionsController
sign_in(user)
generate_templates_project
flash[:notice] = t('devise.sessions.signed_in')
redirect_to stored_location_for(:user) || root_path
redirect_to params[:initial_page] || root_path
else
flash.now[:alert] = t('devise.sessions.2fa.error_message')
render :two_factor_auth

View file

@ -5,6 +5,7 @@
<div class="center-block center-block-narrow">
<h1 class="log-in-title"><%= t "devise.sessions.2fa.title" %></h1>
<%= form_with url: users_authenticate_with_two_factor_url, local: true do %>
<%= hidden_field_tag :initial_page, @initial_page %>
<p><%= t "devise.sessions.2fa.description" %></p>
<p class="input-group sci-input-container">
<%= label :otp, t("devise.sessions.2fa.field") %>