diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-05-14 14:24:05 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-05-14 14:24:05 -0400 |
commit | c802d8eee171d3e4c0cd7e6a16f69f1001255d07 (patch) | |
tree | c3f41c33e644b04a4cd9bf2aaa5f3084ac62e0c7 /app/controllers/concerns | |
parent | 37bc4bb19934c4a0eb84fd5e2556363f55d4d601 (diff) | |
download | gitlab-ce-c802d8eee171d3e4c0cd7e6a16f69f1001255d07.tar.gz |
Refactor SessionsController to use a controller concernrs-refactor-2fa
Diffstat (limited to 'app/controllers/concerns')
-rw-r--r-- | app/controllers/concerns/authenticates_with_two_factor.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/controllers/concerns/authenticates_with_two_factor.rb b/app/controllers/concerns/authenticates_with_two_factor.rb new file mode 100644 index 00000000000..d5918a7af3b --- /dev/null +++ b/app/controllers/concerns/authenticates_with_two_factor.rb @@ -0,0 +1,30 @@ +# == AuthenticatesWithTwoFactor +# +# Controller concern to handle two-factor authentication +# +# Upon inclusion, skips `require_no_authentication` on `:create`. +module AuthenticatesWithTwoFactor + extend ActiveSupport::Concern + + included do + # This action comes from DeviseController, but because we call `sign_in` + # manually, not skipping this action would cause a "You are already signed + # in." error message to be shown upon successful login. + skip_before_action :require_no_authentication, only: [:create] + end + + # Store the user's ID in the session for later retrieval and render the + # two factor code prompt + # + # The user must have been authenticated with a valid login and password + # before calling this method! + # + # user - User record + # + # Returns nil + def prompt_for_two_factor(user) + session[:otp_user_id] = user.id + + render 'devise/sessions/two_factor' and return + end +end |