Browse Source

Merge pull request #143 from Kevinrob/patch-1

Return JSON with 'redirect_to' when handle_failed_second_factor
master
Dmitrii Golub 6 years ago committed by GitHub
parent
commit
7d4940044f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      lib/two_factor_authentication/controllers/helpers.rb

11
lib/two_factor_authentication/controllers/helpers.rb

@ -20,9 +20,14 @@ module TwoFactorAuthentication
end end
def handle_failed_second_factor(scope) def handle_failed_second_factor(scope)
if request.format.present? and request.format.html? if request.format.present?
session["#{scope}_return_to"] = request.original_fullpath if request.get? if request.format.html?
redirect_to two_factor_authentication_path_for(scope) session["#{scope}_return_to"] = request.original_fullpath if request.get?
redirect_to two_factor_authentication_path_for(scope)
elsif request.format.json?
session["#{scope}_return_to"] = root_path(format: :html)
render json: { redirect_to: two_factor_authentication_path_for(scope) }, status: :unauthorized
end
else else
head :unauthorized head :unauthorized
end end

Loading…
Cancel
Save