Module: Devise::Models::GoogleAuthenticatable::InstanceMethods
- Defined in:
- lib/devise_gauth/models/google_authenticatable.rb
Instance Method Summary collapse
- #assign_tmp ⇒ Object
- #get_qr ⇒ Object
- #require_token?(cookie) ⇒ Boolean
- #set_gauth_enabled(param) ⇒ Object
- #validate_token(token) ⇒ Object
-
#with_totp_authentication? ⇒ Boolean
Is the TOTP Authentication enabled.
Instance Method Details
#assign_tmp ⇒ Object
37 38 39 40 41 |
# File 'lib/devise_gauth/models/google_authenticatable.rb', line 37 def assign_tmp update(gauth_tmp: ROTP::Base32.random_base32(32), gauth_tmp_datetime: Time.now) gauth_tmp end |
#get_qr ⇒ Object
29 30 31 |
# File 'lib/devise_gauth/models/google_authenticatable.rb', line 29 def get_qr gauth_secret end |
#require_token?(cookie) ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/devise_gauth/models/google_authenticatable.rb', line 58 def require_token?() return true if self.class.ga_remembertime.nil? || .blank? array = .to_s.split ',' return true if array.count != 2 last_logged_in_email = array[0] last_logged_in_time = array[1].to_i last_logged_in_email != email || (Time.now.to_i - last_logged_in_time) > self.class.ga_remembertime .to_i end |
#set_gauth_enabled(param) ⇒ Object
33 34 35 |
# File 'lib/devise_gauth/models/google_authenticatable.rb', line 33 def set_gauth_enabled(param) update(gauth_enabled: param) end |
#validate_token(token) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/devise_gauth/models/google_authenticatable.rb', line 43 def validate_token(token) return false if gauth_tmp_datetime.nil? return false if gauth_tmp_datetime < self.class.ga_timeout.ago valid_vals = [] valid_vals << ROTP::TOTP.new(get_qr).at(Time.now) (1..self.class.ga_timedrift).each do |cc| valid_vals << ROTP::TOTP.new(get_qr).at(Time.now.ago(30 * cc)) valid_vals << ROTP::TOTP.new(get_qr).at(Time.now.in(30 * cc)) end valid_vals.include?(token.to_i) end |
#with_totp_authentication? ⇒ Boolean
Is the TOTP Authentication enabled
25 26 27 |
# File 'lib/devise_gauth/models/google_authenticatable.rb', line 25 def with_totp_authentication? gauth_enabled.to_i != 0 end |