mirror of
https://github.com/mastodon/mastodon.git
synced 2026-08-24 03:26:27 -05:00
Add ability to require 2FA for specific roles (including Everybody) (#37701)
This commit is contained in:
@@ -61,19 +61,25 @@ class ApplicationController < ActionController::Base
|
||||
return if request.referer.blank?
|
||||
|
||||
redirect_uri = URI(request.referer)
|
||||
return if redirect_uri.path.start_with?('/auth')
|
||||
return if redirect_uri.path.start_with?('/auth', '/settings/two_factor_authentication', '/settings/otp_authentication')
|
||||
|
||||
stored_url = redirect_uri.to_s if redirect_uri.host == request.host && redirect_uri.port == request.port
|
||||
|
||||
store_location_for(:user, stored_url)
|
||||
end
|
||||
|
||||
def mfa_setup_path(path_params = {})
|
||||
settings_two_factor_authentication_methods_path(path_params)
|
||||
end
|
||||
|
||||
def require_functional!
|
||||
return if current_user.functional?
|
||||
|
||||
respond_to do |format|
|
||||
format.any do
|
||||
if current_user.confirmed?
|
||||
if current_user.missing_2fa?
|
||||
redirect_to mfa_setup_path
|
||||
elsif current_user.confirmed?
|
||||
redirect_to edit_user_registration_path
|
||||
else
|
||||
redirect_to auth_setup_path
|
||||
@@ -85,6 +91,8 @@ class ApplicationController < ActionController::Base
|
||||
render json: { error: 'Your login is missing a confirmed e-mail address' }, status: 403
|
||||
elsif !current_user.approved?
|
||||
render json: { error: 'Your login is currently pending approval' }, status: 403
|
||||
elsif current_user.missing_2fa?
|
||||
render json: { error: 'Your account requires two-factor authentication' }, status: 403
|
||||
elsif !current_user.functional?
|
||||
render json: { error: 'Your login is currently disabled' }, status: 403
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user