summaryrefslogtreecommitdiffstats
path: root/app/controllers/twofa_controller.rb
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2020-08-29 06:37:09 +0000
committerGo MAEDA <maeda@farend.jp>2020-08-29 06:37:09 +0000
commitbe7f5e21faa05bdc483d1b58c8887ff499082073 (patch)
tree3eb76db7dfd87ad1b41494261d54b48f0d3ac09f /app/controllers/twofa_controller.rb
parent560bca344ae467cda03e758159fbf131d5c49f43 (diff)
downloadredmine-be7f5e21faa05bdc483d1b58c8887ff499082073.tar.gz
redmine-be7f5e21faa05bdc483d1b58c8887ff499082073.zip
Adds a setting to disable/enable/require 2fa auth (#1237).
Patch by Felix Schäfer. git-svn-id: http://svn.redmine.org/redmine/trunk@19989 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/twofa_controller.rb')
-rw-r--r--app/controllers/twofa_controller.rb18
1 files changed, 13 insertions, 5 deletions
diff --git a/app/controllers/twofa_controller.rb b/app/controllers/twofa_controller.rb
index 4cdeeee4f..8bbdb8056 100644
--- a/app/controllers/twofa_controller.rb
+++ b/app/controllers/twofa_controller.rb
@@ -23,16 +23,20 @@ class TwofaController < ApplicationController
before_action :require_login
before_action :require_admin, only: :admin_deactivate
+ before_action :require_active_twofa
+
require_sudo_mode :activate_init, :deactivate_init
+ skip_before_action :check_twofa_activation, only: [:select_scheme, :activate_init, :activate_confirm, :activate]
+
+ def select_scheme
+ @user = User.current
+ end
+
before_action :activate_setup, only: [:activate_init, :activate_confirm, :activate]
def activate_init
- @twofa.init_pairing!
- if @twofa.send_code(controller: 'twofa', action: 'activate')
- flash[:notice] = l('twofa_code_sent')
- end
- redirect_to action: :activate_confirm, scheme: @twofa.scheme_name
+ init_twofa_pairing_and_send_code_for(@twofa)
end
def activate_confirm
@@ -106,4 +110,8 @@ class TwofaController < ApplicationController
redirect_to my_account_path
end
end
+
+ def require_active_twofa
+ Setting.twofa? ? true : deny_access
+ end
end