mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-29 11:45:18 +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
|
end
|
||||||
|
|
||||||
def two_factor_qr_code
|
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_url = ROTP::TOTP.new(current_user.otp_secret, issuer: 'SciNote').provisioning_uri(current_user.email)
|
||||||
qr_code = RQRCode::QRCode.new(qr_code_url)
|
qr_code = RQRCode::QRCode.new(qr_code_url)
|
||||||
render json: { qr_code: qr_code.as_svg }
|
render json: { qr_code: qr_code.as_svg }
|
||||||
|
|
|
@ -628,9 +628,7 @@ class User < ApplicationRecord
|
||||||
totp.verify(otp, drift_behind: 10)
|
totp.verify(otp, drift_behind: 10)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_2fa_token!
|
def assign_2fa_token!
|
||||||
return if otp_secret
|
|
||||||
|
|
||||||
self.otp_secret = ROTP::Base32.random
|
self.otp_secret = ROTP::Base32.random
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
|
@ -335,7 +335,7 @@ describe User, type: :model do
|
||||||
describe 'valid_otp?' do
|
describe 'valid_otp?' do
|
||||||
let(:user) { create :user }
|
let(:user) { create :user }
|
||||||
before do
|
before do
|
||||||
user.ensure_2fa_token!
|
user.assign_2fa_token!
|
||||||
allow_any_instance_of(ROTP::TOTP).to receive(:verify).and_return(nil)
|
allow_any_instance_of(ROTP::TOTP).to receive(:verify).and_return(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue