Skip to content
This repository has been archived by the owner on Mar 21, 2019. It is now read-only.

proxy and non-heroku ip address capture #43

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ def handle_ip
# Prevent someone from gaming the site by referring themselves.
# Presumably, users are doing this from the same device so block
# their ip after their ip appears three times in the database.
# Using split.first in case client is behind proxy to get his ip.
# If app is deployed on standalone server use request.remote_ip to
# get client ip address.

address = request.env['HTTP_X_FORWARDED_FOR']
address = request.env.fetch('HTTP_X_FORWARDED_FOR', request.remote_ip).split(', ').first
return if address.nil?

current_ip = IpAddress.find_by_address(address)
Expand Down