Class: Twofactor::TwoStep
- Inherits:
-
Object
- Object
- Twofactor::TwoStep
- Defined in:
- lib/twofactor.rb
Class Method Summary collapse
- .disable_twofactor_auth(model_object) ⇒ Object
- .enable_twofactor_auth(model_object) ⇒ Object
- .valid_code?(model_object, code) ⇒ Boolean
Class Method Details
.disable_twofactor_auth(model_object) ⇒ Object
12 13 14 15 16 |
# File 'lib/twofactor.rb', line 12 def self.disable_twofactor_auth(model_object) model_object.update_attribute(Rails.application.class::TWOFACTOR_SECRET_ATTRIBUTE, nil) model_object.update_attribute(Rails.application.class::TWOFACTOR_FLAG_ATTRIBUTE, false) return true end |
.enable_twofactor_auth(model_object) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/twofactor.rb', line 6 def self.enable_twofactor_auth(model_object) model_object.update_attribute(Rails.application.class::TWOFACTOR_SECRET_ATTRIBUTE, ::Base32.encode(rand(36**6).to_s(36))) model_object.update_attribute(Rails.application.class::TWOFACTOR_FLAG_ATTRIBUTE, true) qrcode = ::RQRCode::QRCode.new("otpauth://totp/#{provider_name}:#{model_object[Rails.application.class::TWOFACTOR_REFERENCE_FIELD]}?secret=#{model_object[Rails.application.class::TWOFACTOR_SECRET_ATTRIBUTE]}&issuer=#{provider_name}", :size => Rails.application.class::TWOFACTOR_QRCODE_SIZE, :level => Rails.application.class::TWOFACTOR_QRCODE_QUALITY.to_sym) return qrcode end |
.valid_code?(model_object, code) ⇒ Boolean
17 18 19 |
# File 'lib/twofactor.rb', line 17 def self.valid_code?(model_object, code) ::TOTP.valid?(model_object[Rails.application.class::TWOFACTOR_SECRET_ATTRIBUTE], code) end |