end
def create
- if current_user.validate_and_consume_otp!(confirmation_params[:code])
+ if current_user.validate_and_consume_otp!(confirmation_params[:otp_attempt])
flash.now[:notice] = I18n.t('two_factor_authentication.enabled_success')
current_user.otp_required_for_login = true
private
def confirmation_params
- params.require(:form_two_factor_confirmation).permit(:code)
+ params.require(:form_two_factor_confirmation).permit(:otp_attempt)
end
def prepare_two_factor_form
private
def confirmation_params
- params.require(:form_two_factor_confirmation).permit(:code)
+ params.require(:form_two_factor_confirmation).permit(:otp_attempt)
end
def verify_otp_required
end
def acceptable_code?
- current_user.validate_and_consume_otp!(confirmation_params[:code]) ||
- current_user.invalidate_otp_backup_code!(confirmation_params[:code])
+ current_user.validate_and_consume_otp!(confirmation_params[:otp_attempt]) ||
+ current_user.invalidate_otp_backup_code!(confirmation_params[:otp_attempt])
end
end
end
class Form::TwoFactorConfirmation
include ActiveModel::Model
- attr_accessor :code
+ attr_accessor :otp_attempt
end
%samp.qr-alternative__code= current_user.otp_secret.scan(/.{4}/).join(' ')
.fields-group
- = f.input :code, wrapper: :with_label, hint: t('two_factor_authentication.code_hint'), label: t('simple_form.labels.defaults.otp_attempt'), input_html: { :autocomplete => 'off' }, required: true
+ = f.input :otp_attempt, wrapper: :with_label, hint: t('two_factor_authentication.code_hint'), label: t('simple_form.labels.defaults.otp_attempt'), input_html: { :autocomplete => 'off' }, required: true
.actions
= f.button :button, t('two_factor_authentication.enable'), type: :submit
%hr/
= simple_form_for @confirmation, url: settings_two_factor_authentication_path, method: :delete do |f|
- = f.input :code, wrapper: :with_label, hint: t('two_factor_authentication.code_hint'), label: t('simple_form.labels.defaults.otp_attempt'), input_html: { :autocomplete => 'off' }, required: true
+ = f.input :otp_attempt, wrapper: :with_label, hint: t('two_factor_authentication.code_hint'), label: t('simple_form.labels.defaults.otp_attempt'), input_html: { :autocomplete => 'off' }, required: true
.actions
= f.button :button, t('two_factor_authentication.disable'), type: :submit
true
end
- post :create, params: { form_two_factor_confirmation: { code: '123456' } }
+ post :create, params: { form_two_factor_confirmation: { otp_attempt: '123456' } }
expect(assigns(:recovery_codes)).to eq otp_backup_codes
expect(flash[:notice]).to eq 'Two-factor authentication successfully enabled'
false
end
- post :create, params: { form_two_factor_confirmation: { code: '123456' } }
+ post :create, params: { form_two_factor_confirmation: { otp_attempt: '123456' } }
end
it 'renders the new view' do
context 'when not signed in' do
it 'redirects if not signed in' do
- post :create, params: { form_two_factor_confirmation: { code: '123456' } }
+ post :create, params: { form_two_factor_confirmation: { otp_attempt: '123456' } }
expect(response).to redirect_to('/auth/sign_in')
end
end
true
end
- post :destroy, params: { form_two_factor_confirmation: { code: '123456' } }
+ post :destroy, params: { form_two_factor_confirmation: { otp_attempt: '123456' } }
expect(response).to redirect_to(settings_two_factor_authentication_path)
user.reload
false
end
- post :destroy, params: { form_two_factor_confirmation: { code: '057772' } }
+ post :destroy, params: { form_two_factor_confirmation: { otp_attempt: '057772' } }
user.reload
expect(user.otp_required_for_login).to eq(true)