Rename ensure 2fa method

This commit is contained in:
aignatov-bio 2020-07-02 11:24:33 +02:00
parent 46256c89c9
commit 9b33cbc104
3 changed files with 3 additions and 5 deletions

View file

@ -201,7 +201,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
end
def two_factor_qr_code
current_user.ensure_2fa_token!
current_user.assign_2fa_token!
qr_code_url = ROTP::TOTP.new(current_user.otp_secret, issuer: 'SciNote').provisioning_uri(current_user.email)
qr_code = RQRCode::QRCode.new(qr_code_url)
render json: { qr_code: qr_code.as_svg }

View file

@ -628,9 +628,7 @@ class User < ApplicationRecord
totp.verify(otp, drift_behind: 10)
end
def ensure_2fa_token!
return if otp_secret
def assign_2fa_token!
self.otp_secret = ROTP::Base32.random
save!
end

View file

@ -335,7 +335,7 @@ describe User, type: :model do
describe 'valid_otp?' do
let(:user) { create :user }
before do
user.ensure_2fa_token!
user.assign_2fa_token!
allow_any_instance_of(ROTP::TOTP).to receive(:verify).and_return(nil)
end