From abbe5f15e1451c3910a2074c6bcdd929f3ce0b6e Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 30 Aug 2023 18:46:47 -0500 Subject: [PATCH] Add meta address key to setting --- dmoj/settings.py | 3 +++ judge/user_log.py | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) 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