Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class TotpVerificationController < ApplicationController

def show
@presenter = presenter_for_two_factor_authentication_method
return unless FeatureManagement.prefill_otp_codes?
@code = ROTP::TOTP.new(current_user.otp_secret_key).now
end

def create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ h1.h3.my0 = @presenter.header
= label_tag 'code', t('simple_form.required.html') + t('forms.two_factor.code'),
class: 'block bold'
.col-12.sm-col-5.mb4.sm-mb0.sm-mr-20p.inline-block
= text_field_tag :code, '', required: true, autofocus: true,
= text_field_tag :code, '', value: @code, required: true, autofocus: true,
pattern: '[0-9]*', class: 'col-12 field monospace mfa', type: 'tel',
'aria-describedby': 'code-instructs', maxlength: Devise.otp_length, autocomplete: 'off'
= submit_tag 'Submit', class: 'btn btn-primary align-top'
Expand Down
13 changes: 13 additions & 0 deletions lib/tasks/dev.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace :dev do
end
end

ee = EncryptedAttribute.new_from_decrypted('totp@test.com')
User.find_or_create_by!(email_fingerprint: ee.fingerprint) do |user|
setup_totp_user(user, ee: ee, pw: pw)
end

loa3_user = User.find_by(email_fingerprint: fingerprint('test2@test.com'))
profile = Profile.new(user: loa3_user)
pii = Pii::Attributes.new_from_hash(
Expand Down Expand Up @@ -89,6 +94,14 @@ namespace :dev do
Event.create(user_id: user.id, event_type: :account_created)
end

def setup_totp_user(user, args)
user.encrypted_email = args[:ee].encrypted
user.skip_confirmation!
user.reset_password(args[:pw], args[:pw])
user.otp_secret_key = ROTP::Base32.random_base32
Event.create(user_id: user.id, event_type: :account_created)
end

def fingerprint(email)
Pii::Fingerprinter.fingerprint(email)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

trait :with_authentication_app do
with_personal_key
otp_secret_key 'abc123'
otp_secret_key ROTP::Base32.random_base32
end

trait :admin do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/tasks/dev_rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
it 'runs successfully' do
Rake::Task['dev:prime'].invoke

expect(User.count).to eq 2
expect(User.count).to eq 3
end
end

Expand Down