Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method for when 2nd factor auth is pending #452

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_partially_authenticated? %>
<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_partially_authenticated?
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_partially_authenticated?
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_partially_authenticated?
logged_in? && !two_factor_authenticated? && uses_two_factor_authentication?
end

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