Add meta address key to setting

This commit is contained in:
cuom1999 2023-08-30 18:46:47 -05:00
parent 1473118c5a
commit abbe5f15e1
2 changed files with 6 additions and 2 deletions

View file

@ -487,3 +487,6 @@ DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
# Chat # Chat
CHAT_SECRET_KEY = "QUdVFsxk6f5-Hd8g9BXv81xMqvIZFRqMl-KbRzztW-U=" CHAT_SECRET_KEY = "QUdVFsxk6f5-Hd8g9BXv81xMqvIZFRqMl-KbRzztW-U="
# Nginx
META_REMOTE_ADDRESS_KEY = "REMOTE_ADDR"

View file

@ -1,4 +1,5 @@
from django.utils.timezone import now from django.utils.timezone import now
from django.conf import settings
from judge.models import Profile from judge.models import Profile
@ -17,8 +18,8 @@ class LogUserAccessMiddleware(object):
): ):
updates = {"last_access": now()} updates = {"last_access": now()}
# Decided on using REMOTE_ADDR as nginx will translate it to the external IP that hits it. # Decided on using REMOTE_ADDR as nginx will translate it to the external IP that hits it.
if request.META.get("REMOTE_ADDR"): if request.META.get(settings.META_REMOTE_ADDRESS_KEY):
updates["ip"] = request.META.get("REMOTE_ADDR") updates["ip"] = request.META.get(settings.META_REMOTE_ADDRESS_KEY)
Profile.objects.filter(user_id=request.user.pk).update(**updates) Profile.objects.filter(user_id=request.user.pk).update(**updates)
return response return response