mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-28 19:24:10 +08:00
Rename ensure 2fa method
This commit is contained in:
parent
46256c89c9
commit
9b33cbc104
3 changed files with 3 additions and 5 deletions
|
@ -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 }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue