diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-24 13:53:13 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-24 13:53:13 +0200 |
| commit | dcb576618b868b888a5b1b31e35491f300ce4050 (patch) | |
| tree | 3a970eae416fba2939cd366b1ba2b5d294154f2c /app/controllers/application_controller.rb | |
| parent | fefec929c59c72dc93e4be30e8f23cd8c5258b0a (diff) | |
Complete the login only after the second factor
Enrolled users get a pending marker instead of a session after the
password step; a valid code through the challenge writes the real
session via reset_session. otp_required without enrollment funnels
into setup everywhere except the enrollment, user, and login
machinery.
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 |
