summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/authenticated_system.rb7
-rw-r--r--lib/authenticated_test_helper.rb6
2 files changed, 9 insertions, 4 deletions
diff --git a/lib/authenticated_system.rb b/lib/authenticated_system.rb
index 04d8051f..668436b5 100644
--- a/lib/authenticated_system.rb
+++ b/lib/authenticated_system.rb
@@ -25,9 +25,10 @@ module AuthenticatedSystem
25 # Tied to is_admin? so losing the role closes the window at once, rather 25 # Tied to is_admin? so losing the role closes the window at once, rather
26 # than leaving a timestamp that would count again if the role returned. 26 # than leaving a timestamp that would count again if the role returned.
27 def elevated? 27 def elevated?
28 return false unless current_user&.is_admin? 28 return false unless current_user&.is_admin?
29 session[:elevated_at].to_i > ELEVATION_MAX_AGE.ago.to_i 29 return false unless current_user.otp_enrolled?
30 end 30 session[:elevated_at].to_i > ELEVATION_MAX_AGE.ago.to_i
31 end
31 32
32 def elevation_expires_at 33 def elevation_expires_at
33 return nil unless elevated? 34 return nil unless elevated?
diff --git a/lib/authenticated_test_helper.rb b/lib/authenticated_test_helper.rb
index 065a5f7d..483e6c88 100644
--- a/lib/authenticated_test_helper.rb
+++ b/lib/authenticated_test_helper.rb
@@ -6,6 +6,10 @@ module AuthenticatedTestHelper
6 end 6 end
7 7
8 def elevate_session! 8 def elevate_session!
9 session[:elevated_at] = Time.now.to_i 9 user = User.find_by(:id => @request.session[:user_id])
10 if user && !user.otp_enrolled?
11 user.update_column(:otp_secret, ROTP::Base32.random)
12 end
13 @request.session[:elevated_at] = Time.now.to_i
10 end 14 end
11end 15end