Skip to content

Commit

Permalink
Add method for when 2nd factor auth is pending
Browse files Browse the repository at this point in the history
  • Loading branch information
janko committed Nov 17, 2024
1 parent eabfa69 commit 48060f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion demo-site/views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<% if rodauth.logged_in_via_remember_key? %>
<li><a href="/confirm-password">Confirm Password</a></li>
<% end %>
<% if rodauth.uses_two_factor_authentication? && !rodauth.two_factor_authenticated? %>
<% if rodauth.two_factor_authentication_pending? %>
<li><a href="/multifactor-auth">Authenticate Using Additional Factor</a></li>
<% else %>
<li><a href="/multifactor-manage">Manage Multifactor Authentication</a></li>
Expand Down
19 changes: 6 additions & 13 deletions lib/rodauth/features/two_factor_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,12 @@ def two_factor_modifications_require_password?
end

def authenticated?
# False if not authenticated via single factor
return false unless super

# True if already authenticated via 2nd factor
return true if two_factor_authenticated?

# True if authenticated via single factor and 2nd factor not setup
!uses_two_factor_authentication?
super && !two_factor_authentication_pending?
end

def require_authentication
super

# Avoid database query if already authenticated via 2nd factor
return if two_factor_authenticated?

require_two_factor_authenticated if uses_two_factor_authentication?
require_two_factor_authenticated if two_factor_authentication_pending?
end

def require_two_factor_setup
Expand Down Expand Up @@ -188,6 +177,10 @@ def two_factor_password_match?(password)
end
end

def two_factor_authentication_pending?
!two_factor_authenticated? && uses_two_factor_authentication?
end

def two_factor_authenticated?
authenticated_by && authenticated_by.length >= 2
end
Expand Down

0 comments on commit 48060f4

Please sign in to comment.