diff --git a/config.dist.yaml b/config.dist.yaml index 943208c..28079d3 100644 --- a/config.dist.yaml +++ b/config.dist.yaml @@ -11,4 +11,5 @@ email: password: your_password tls: true admin: - email: admin@your.server \ No newline at end of file + email: admin@your.server +trust_proxy: false \ No newline at end of file diff --git a/src/synapse_registration/registration/views.py b/src/synapse_registration/registration/views.py index ee30b59..bd6d3e5 100644 --- a/src/synapse_registration/registration/views.py +++ b/src/synapse_registration/registration/views.py @@ -52,11 +52,17 @@ class EmailInputView(FormView): return self.form_invalid(form) token = token_urlsafe(32) + + if not settings.TRUST_PROXY: + ip_address = self.request.META.get("REMOTE_ADDR") + else: + ip_address = self.request.META.get("HTTP_X_FORWARDED_FOR") + UserRegistration.objects.create( username=self.request.session["username"], email=email, token=token, - ip_address=self.request.META.get("REMOTE_ADDR"), + ip_address=ip_address, ) verification_link = self.request.build_absolute_uri( reverse_lazy("verify_email", args=[token]) diff --git a/src/synapse_registration/synapse_registration/settings.py b/src/synapse_registration/synapse_registration/settings.py index 469f13b..856f71a 100644 --- a/src/synapse_registration/synapse_registration/settings.py +++ b/src/synapse_registration/synapse_registration/settings.py @@ -47,6 +47,8 @@ DEBUG = config.get("debug", False) ALLOWED_HOSTS = config.get("hosts") +TRUST_PROXY = config.get("trust_proxy", False) + if not ALLOWED_HOSTS: raise KeyError("Please specify a list of allowed hosts in the configuration file.")