use HTTP_X_FORWARDED_FOR as ip of set

This commit is contained in:
j 2013-08-30 10:38:45 +02:00
parent 8ceae868b1
commit 7c6757f417

View file

@ -106,6 +106,9 @@ class SessionData(models.Model):
data, created = cls.objects.get_or_create(session_key=session_key) data, created = cls.objects.get_or_create(session_key=session_key)
if request.user.is_authenticated(): if request.user.is_authenticated():
data.user = request.user data.user = request.user
if 'HTTP_X_FORWARDED_FOR' in request.META:
data.ip = request.META['HTTP_X_FORWARDED_FOR']
else:
data.ip = request.META['REMOTE_ADDR'] data.ip = request.META['REMOTE_ADDR']
if data.ip.startswith('::ffff:'): if data.ip.startswith('::ffff:'):
data.ip = data.ip[len('::ffff:'):] data.ip = data.ip[len('::ffff:'):]