Module: Devise::Models::GoogleAuthenticatable::InstanceMethods
- Defined in:
- lib/devise_google_authenticatable/models/google_authenticatable.rb
Overview
:nodoc:
Instance Method Summary collapse
- #assign_tmp ⇒ Object
- #get_qr ⇒ Object
- #set_gauth_enabled(params) ⇒ Object
- #validate_token(token) ⇒ Object
Instance Method Details
#assign_tmp ⇒ Object
26 27 28 29 |
# File 'lib/devise_google_authenticatable/models/google_authenticatable.rb', line 26 def assign_tmp self.update_attributes(:gauth_tmp => ROTP::Base32.random_base32(32), :gauth_tmp_datetime => DateTime.now) self.gauth_tmp end |
#get_qr ⇒ Object
18 19 20 |
# File 'lib/devise_google_authenticatable/models/google_authenticatable.rb', line 18 def get_qr self.gauth_secret end |
#set_gauth_enabled(params) ⇒ Object
22 23 24 |
# File 'lib/devise_google_authenticatable/models/google_authenticatable.rb', line 22 def set_gauth_enabled(params) self.update_without_password(params) end |
#validate_token(token) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/devise_google_authenticatable/models/google_authenticatable.rb', line 31 def validate_token(token) return false if self.gauth_tmp_datetime.nil? if self.gauth_tmp_datetime < self.class.ga_timeout.ago return false else valid_vals = [] valid_vals << ROTP::TOTP.new(self.get_qr).at(Time.now) (1..self.class.ga_timedrift).each do |cc| valid_vals << ROTP::TOTP.new(self.get_qr).at(Time.now.ago(30*cc)) valid_vals << ROTP::TOTP.new(self.get_qr).at(Time.now.in(30*cc)) end if valid_vals.include?(token.to_i) return true else return false end end end |