Module: Devise::Models::GoogleAuthenticatable::InstanceMethods

Defined in:
lib/devise_gauth/models/google_authenticatable.rb

Instance Method Summary collapse

Instance Method Details

#assign_tmpObject



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_qrObject



29
30
31
# File 'lib/devise_gauth/models/google_authenticatable.rb', line 29

def get_qr
  gauth_secret
end

#require_token?(cookie) ⇒ Boolean

Returns:

  • (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?(cookie)
  return true if self.class.ga_remembertime.nil? || cookie.blank?

  array = cookie.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

Returns:

  • (Boolean)


25
26
27
# File 'lib/devise_gauth/models/google_authenticatable.rb', line 25

def with_totp_authentication?
  gauth_enabled.to_i != 0
end