diff --git a/dmoj/settings.py b/dmoj/settings.py index d03dc27..713e31c 100644 --- a/dmoj/settings.py +++ b/dmoj/settings.py @@ -487,3 +487,6 @@ DEFAULT_AUTO_FIELD = "django.db.models.AutoField" # Chat CHAT_SECRET_KEY = "QUdVFsxk6f5-Hd8g9BXv81xMqvIZFRqMl-KbRzztW-U=" + +# Nginx +META_REMOTE_ADDRESS_KEY = "REMOTE_ADDR" diff --git a/judge/user_log.py b/judge/user_log.py index 91a4c67..b8aec43 100644 --- a/judge/user_log.py +++ b/judge/user_log.py @@ -1,4 +1,5 @@ from django.utils.timezone import now +from django.conf import settings from judge.models import Profile @@ -17,8 +18,8 @@ class LogUserAccessMiddleware(object): ): updates = {"last_access": now()} # Decided on using REMOTE_ADDR as nginx will translate it to the external IP that hits it. - if request.META.get("REMOTE_ADDR"): - updates["ip"] = request.META.get("REMOTE_ADDR") + if request.META.get(settings.META_REMOTE_ADDRESS_KEY): + updates["ip"] = request.META.get(settings.META_REMOTE_ADDRESS_KEY) Profile.objects.filter(user_id=request.user.pk).update(**updates) return response