Module: Devise::Models::TwoFactorAuthenticatable::InstanceMethodsOnActivation
- Defined in:
- lib/two_factor_authentication/models/two_factor_authenticatable.rb
Instance Method Summary collapse
- #authenticate_otp(code, options = {}) ⇒ Object
- #max_login_attempts ⇒ Object
- #max_login_attempts? ⇒ Boolean
- #need_two_factor_authentication?(request) ⇒ Boolean
- #otp_code(time = Time.now, options = {}) ⇒ Object
- #populate_otp_column ⇒ Object
- #provisioning_uri(account = nil, options = {}) ⇒ Object
- #send_two_factor_authentication_code ⇒ Object
Instance Method Details
#authenticate_otp(code, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 24 def authenticate_otp(code, = {}) totp = ROTP::TOTP.new( otp_secret_key, digits: [:otp_length] || self.class.otp_length ) drift = [:drift] || self.class.allowed_otp_drift_seconds totp.verify_with_drift(code, drift) end |
#max_login_attempts ⇒ Object
57 58 59 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 57 def max_login_attempts self.class.max_login_attempts end |
#max_login_attempts? ⇒ Boolean
53 54 55 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 53 def max_login_attempts? second_factor_attempts_count.to_i >= max_login_attempts.to_i end |
#need_two_factor_authentication?(request) ⇒ Boolean
45 46 47 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 45 def need_two_factor_authentication?(request) true end |
#otp_code(time = Time.now, options = {}) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 33 def otp_code(time = Time.now, = {}) ROTP::TOTP.new( otp_secret_key, digits: [:otp_length] || self.class.otp_length ).at(time, true) end |
#populate_otp_column ⇒ Object
61 62 63 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 61 def populate_otp_column self.otp_secret_key = ROTP::Base32.random_base32 end |
#provisioning_uri(account = nil, options = {}) ⇒ Object
40 41 42 43 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 40 def provisioning_uri(account = nil, = {}) account ||= self.email if self.respond_to?(:email) ROTP::TOTP.new(otp_secret_key, ).provisioning_uri(account) end |
#send_two_factor_authentication_code ⇒ Object
49 50 51 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 49 def send_two_factor_authentication_code raise NotImplementedError.new("No default implementation - please define in your class.") end |