Module: ActiveModel::OneTimePassword::InstanceMethodsOnActivation
- Defined in:
- lib/active_model/one_time_password.rb
Instance Method Summary collapse
- #authenticate_otp(code, options = {}) ⇒ Object
- #otp_code(time = Time.now) ⇒ Object
- #otp_column ⇒ Object
- #otp_column=(attr) ⇒ Object
- #provisioning_uri(account = nil) ⇒ Object
Instance Method Details
#authenticate_otp(code, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/active_model/one_time_password.rb', line 24 def authenticate_otp(code, = {}) totp = ROTP::TOTP.new(self.otp_column) if drift = [:drift] totp.verify_with_drift(code, drift) else totp.verify(code) end end |
#otp_code(time = Time.now) ⇒ Object
33 34 35 |
# File 'lib/active_model/one_time_password.rb', line 33 def otp_code(time = Time.now) ROTP::TOTP.new(self.otp_column).at(time) end |
#otp_column ⇒ Object
42 43 44 |
# File 'lib/active_model/one_time_password.rb', line 42 def otp_column self.send(self.class.otp_column_name) end |
#otp_column=(attr) ⇒ Object
46 47 48 |
# File 'lib/active_model/one_time_password.rb', line 46 def otp_column=(attr) self.send("#{self.class.otp_column_name}=", attr) end |
#provisioning_uri(account = nil) ⇒ Object
37 38 39 40 |
# File 'lib/active_model/one_time_password.rb', line 37 def provisioning_uri(account = nil) account ||= self.email if self.respond_to?(:email) ROTP::TOTP.new(self.otp_column).provisioning_uri(account) end |