feat: Add trust proxy configuration support
Introduces a 'trust_proxy' setting in the configuration file to handle client IP addresses correctly. Updates logic in the EmailInputView to extract the client IP based on trust proxy settings, improving flexibility for deployments behind proxies. Relates to handling requests within various network environments.
This commit is contained in:
parent
26664be144
commit
c3794bd1b6
3 changed files with 11 additions and 2 deletions
|
@ -12,3 +12,4 @@ email:
|
|||
tls: true
|
||||
admin:
|
||||
email: admin@your.server
|
||||
trust_proxy: false
|
|
@ -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])
|
||||
|
|
|
@ -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.")
|
||||
|
||||
|
|
Loading…
Reference in a new issue