-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This patch adds an `ip_address` field to the SlackMembershipSubmission model which gets set to the clients IP address upon form submission. It is then displayed in the admin screens when reviewing submissions showing the city, region, and country. It utilizes the free service from http://ip-api.com test plan: - % bundle install - % rails s - delete any pending membership submissions you have locally % rails runner SlackMembershipSubmission.delete_all - visit home page - click 'join now' button - fill out form and submit - go to /admin - go to pending submissions - note that under the 'Location' field there isn't any additional text. - open rails console and tweak your submission to give it a public ip address: % rails c > sms = SlackMembershipSubmission.first > sms.ip_address = "73.11.237.17" > sms.save! - reload pending submissions screen - note that under 'Location' field it now says 'Olympia, WA, United States'
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# See http://ip-api.com/docs/api:json | ||
# | ||
class IpInfo | ||
def initialize(ip_address) | ||
@ip_address = ip_address | ||
@info = JSON.parse(Net::HTTP.get("ip-api.com", "/json/#{@ip_address}")) | ||
end | ||
|
||
def successful? | ||
@info["status"] == "success" | ||
end | ||
|
||
def method_missing(symbol, *args) | ||
key = symbol.to_s.camelize(:lower) | ||
return @info[key] if @info.key?(key) | ||
super | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddIpAddressToSlackMembershipSubmissions < ActiveRecord::Migration[5.1] | ||
def change | ||
add_column :slack_membership_submissions, :ip_address, :inet | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.