diff options
Diffstat (limited to 'app/controllers/application_controller.rb')
| -rw-r--r-- | app/controllers/application_controller.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d8de9750..6d46d522 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb | |||
| @@ -4,6 +4,7 @@ class ApplicationController < ActionController::Base | |||
| 4 | protect_from_forgery | 4 | protect_from_forgery |
| 5 | 5 | ||
| 6 | before_action :set_locale | 6 | before_action :set_locale |
| 7 | before_action :enforce_otp_enrollment | ||
| 7 | 8 | ||
| 8 | helper_method :safe_return_to | 9 | helper_method :safe_return_to |
| 9 | 10 | ||
| @@ -30,4 +31,16 @@ class ApplicationController < ActionController::Base | |||
| 30 | rescue URI::InvalidURIError | 31 | rescue URI::InvalidURIError |
| 31 | default | 32 | default |
| 32 | end | 33 | end |
| 34 | |||
| 35 | # The hard gate for the slow transition: a user flagged otp_required | ||
| 36 | # who has not enrolled can reach only enrollment, their own user page, | ||
| 37 | # the login machinery, and the challenge -- everything else funnels | ||
| 38 | # into setup. Anonymous visitors are untouched (not logged_in?). | ||
| 39 | def enforce_otp_enrollment | ||
| 40 | return unless logged_in? | ||
| 41 | return unless current_user.otp_required? && !current_user.otp_enrolled? | ||
| 42 | return if %w[otp_enrollments otp_challenges sessions users].include?(controller_name) | ||
| 43 | flash[:error] = "Your account requires a second factor -- set it up to continue." | ||
| 44 | redirect_to edit_user_path(current_user) | ||
| 45 | end | ||
| 33 | end | 46 | end |
