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
- #otp_column ⇒ Object
- #otp_column=(attr) ⇒ 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
27 28 29 30 31 32 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 27 def authenticate_otp(code, = {}) totp = ROTP::TOTP.new(self.otp_column, { 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
63 64 65 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 63 def max_login_attempts self.class.max_login_attempts end |
#max_login_attempts? ⇒ Boolean
59 60 61 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 59 def max_login_attempts? second_factor_attempts_count.to_i >= max_login_attempts.to_i end |
#need_two_factor_authentication?(request) ⇒ Boolean
51 52 53 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 51 def need_two_factor_authentication?(request) true end |
#otp_code(time = Time.now, options = {}) ⇒ Object
34 35 36 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 34 def otp_code(time = Time.now, = {}) ROTP::TOTP.new(self.otp_column, { digits: [:otp_length] || self.class.otp_length }).at(time, true) end |
#otp_column ⇒ Object
43 44 45 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 43 def otp_column self.send(self.class.otp_column_name) end |
#otp_column=(attr) ⇒ Object
47 48 49 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 47 def otp_column=(attr) self.send("#{self.class.otp_column_name}=", attr) end |
#populate_otp_column ⇒ Object
67 68 69 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 67 def populate_otp_column self.otp_column = ROTP::Base32.random_base32 end |
#provisioning_uri(account = nil, options = {}) ⇒ Object
38 39 40 41 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 38 def provisioning_uri(account = nil, = {}) account ||= self.email if self.respond_to?(:email) ROTP::TOTP.new(self.otp_column, ).provisioning_uri(account) end |
#send_two_factor_authentication_code ⇒ Object
55 56 57 |
# File 'lib/two_factor_authentication/models/two_factor_authenticatable.rb', line 55 def send_two_factor_authentication_code raise NotImplementedError.new("No default implementation - please define in your class.") end |