Closed DeeeeLAN closed 3 years ago
I bring it up because nginx is causing IP_ADDR to be set to null, so the .get call doesn't set it to the default 0.0.0.0.
I added the storing of an IP address with the signup code, in case the application programmer wants to take action if multiple signup codes are being requested from the same IP address.
How do you propose the getting the IP address of the client?
Alternately, I could check if ipaddr is null and set it to 0.0.0.0.
As mentioned in that post, this seems like it is probably your best bet, it will handle all the various address locations for you:
https://github.com/un33k/django-ipware#notice
But since there isn’t really a good defense against spoofing, I think it would be nice to have an option to just disable it as well. Make the database key optional and just skip it if I disable it.
Great. Do you think this would be sufficient?
from ipware import get_client_ip
...
client_ip = get_client_ip(request)[0]
if client_ip is None:
client_ip = '0.0.0.0' # Unable to get the client's IP address
signup_code = SignupCode.objects.create_signup_code(user, client_ip)
...
Makes sense to me. I will let you know if it works on my end.
Great. Works on my end. LMK.
@DeeeeLAN Any luck getting it to work on your end?
Sorry, I have been working on other things and haven't had time to get around to testing this. I will try and work on it and get it tested this week.
Closing due to inactivity.
I finally got around to testing this and I can confirm it has fixed the failures I was seeing, if you want to merge it into master.
Fixed with #54
Hi,
My server is throwing the following exception:
I was looking for solutions online and stumbled on this post from a long time ago indicating the 'REMOTE_ADDR' field is really bad practice to use: https://www.djangoproject.com/weblog/2009/jul/28/security/#secondary-issue
See more here: https://stackoverflow.com/questions/4581789/how-do-i-get-user-ip-address-in-django
Is the IP address necessary? I noticed it gets saved with the code to the database, but as far as I can tell it isn't used for anything after that.