Commit 8ae712ae authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets Committed by Robert Speicher

Render 2fa recovery codes instead of downloading it

parent 802fcd05
...@@ -11,9 +11,10 @@ class Profiles::TwoFactorAuthsController < ApplicationController ...@@ -11,9 +11,10 @@ class Profiles::TwoFactorAuthsController < ApplicationController
def create def create
if current_user.valid_otp?(params[:pin_code]) if current_user.valid_otp?(params[:pin_code])
current_user.otp_required_for_login = true current_user.otp_required_for_login = true
@codes = current_user.generate_otp_backup_codes!
current_user.save! current_user.save!
redirect_to profile_account_path render 'create'
else else
@error = 'Invalid pin code' @error = 'Invalid pin code'
@qr_code = build_qr_code @qr_code = build_qr_code
...@@ -22,9 +23,8 @@ class Profiles::TwoFactorAuthsController < ApplicationController ...@@ -22,9 +23,8 @@ class Profiles::TwoFactorAuthsController < ApplicationController
end end
def codes def codes
codes = current_user.generate_otp_backup_codes! @codes = current_user.generate_otp_backup_codes!
current_user.save! current_user.save!
send_data codes.join("\n"), filename: 'gitlab_recovery_codes.txt'
end end
def destroy def destroy
......
...@@ -35,14 +35,11 @@ ...@@ -35,14 +35,11 @@
%div %div
.pull-right .pull-right
= link_to "Disable 2-Factor Authentication", profile_two_factor_auth_path, method: :delete, class: 'btn btn-close btn-sm' = link_to "Disable 2-Factor Authentication", profile_two_factor_auth_path, method: :delete, class: 'btn btn-close btn-sm'
%p.slead %p
%i.fa.fa-warning If you lost your recovery codes - you can
Please %strong
%strong #{link_to "download recovery codes", codes_profile_two_factor_auth_path} = link_to "generate new one", codes_profile_two_factor_auth_path, method: :post,
so you can access your account if you lose your phone. data: { confirm: 'After we generate new recovery codes - old codes will not be valid any more. Are you sure?' }
%br
%i.fa.fa-warning
Every time you download recovery codes - we generate the new codes. Previously downloaded codes won't work anymore.
- else - else
%legend Two-Factor Authentication %legend Two-Factor Authentication
......
%p.slead
Please save this recovery codes so you can access your account if you lose your phone.
.codes.well
%ul
- @codes.each do |code|
%li
%span.monospace
= code
= link_to profile_account_path, class: 'btn btn-success' do
I saved the codes
%h3.page-title Two-Factor Authentication Recovery codes
%hr
= render 'codes'
.alert.alert-success
Congratulations! You have enabled Two-Factor Authentication!
= render 'codes'
...@@ -228,7 +228,7 @@ Gitlab::Application.routes.draw do ...@@ -228,7 +228,7 @@ Gitlab::Application.routes.draw do
resource :avatar, only: [:destroy] resource :avatar, only: [:destroy]
resource :two_factor_auth, only: [:new, :create, :destroy] do resource :two_factor_auth, only: [:new, :create, :destroy] do
member do member do
get :codes post :codes
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment