Module: Devise::Models::PasswordSharing

Extended by:
ActiveSupport::Concern
Defined in:
lib/devise_password_sharing_extension/models/password_sharing.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#ban_for_password_sharing!Object



43
44
45
46
47
# File 'lib/devise_password_sharing_extension/models/password_sharing.rb', line 43

def ban_for_password_sharing!
  return unless self.class.enable_banning
  self.banned_for_password_sharing_at = Time.now
  save(validate: false)
end

#create_login_event!(remote_ip) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/devise_password_sharing_extension/models/password_sharing.rb', line 23

def (remote_ip)
  unless @@white_listed_ips.include?(remote_ip)
    database = GeoIP.new(self.class.geoip_database)
    if geo = database.city(remote_ip)
      begin
        .create!(
          ip_address: remote_ip,
          latitude: geo.latitude,
          longitude: geo.longitude,
          city: geo.city_name.encode('US-ASCII', undef: :replace),
          country_code: geo.country_code2.encode('US-ASCII', undef: :replace),
          region_name: geo.region_name.encode('US-ASCII', undef: :replace))
      rescue ActiveRecord::RecordInvalid => e
        # Just move on and be nice.
        Rails.logger.info("Problem with geo: #{geo.inspect}")
      end
    end
  end
end

#password_sharing?Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/devise_password_sharing_extension/models/password_sharing.rb', line 49

def password_sharing?
  return true unless banned_for_password_sharing_at.nil?
  .cities_in_the_last(self.class.time_frame).count >= self.class.number_of_cities
end