Class: User::User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- User::User
- Defined in:
- app/models/user/user.rb
Instance Method Summary collapse
Instance Method Details
#hotp ⇒ Object
22 23 24 |
# File 'app/models/user/user.rb', line 22 def hotp ROTP::HOTP.new(hotp_token) end |
#mint_otp ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/models/user/user.rb', line 26 def mint_otp self.otp_counter += 1 otp = hotp.at(self.otp_counter) self.otp_last_minted = Time.now.to_i save! otp end |
#use_otp(token) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/user/user.rb', line 35 def use_otp(token) if !begin hotp.verify(token.to_s, self.otp_counter.to_i) rescue nil end.nil? && Time.now.to_i <= otp_last_minted + 600 self.otp_last_minted = nil self.otp_counter += 1 true else false end end |