Skip to content

Commit

Permalink
refactor(account/adapter): Populate current_site at send_mail
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Dec 8, 2023
1 parent a364868 commit 0c99d5f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 5 additions & 4 deletions allauth/account/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ def render_mail(self, template_prefix, email, context, headers=None):
return msg

def send_mail(self, template_prefix, email, context):
msg = self.render_mail(template_prefix, email, context)
ctx = {
"current_site": get_current_site(globals()["context"].request),
}
ctx.update(context)
msg = self.render_mail(template_prefix, email, ctx)
msg.send()

def get_signup_redirect_url(self, request):
Expand Down Expand Up @@ -606,20 +610,17 @@ def send_account_already_exists_mail(self, email):
)
ctx = {
"request": context.request,
"current_site": get_current_site(context.request),
"email": email,
"signup_url": signup_url,
"password_reset_url": password_reset_url,
}
self.send_mail("account/email/account_already_exists", email, ctx)

def send_confirmation_mail(self, request, emailconfirmation, signup):
current_site = get_current_site(request)
activate_url = self.get_email_confirmation_url(request, emailconfirmation)
ctx = {
"user": emailconfirmation.email_address.user,
"activate_url": activate_url,
"current_site": current_site,
"key": emailconfirmation.key,
}
if signup:
Expand Down
3 changes: 0 additions & 3 deletions allauth/account/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django import forms
from django.contrib.auth import password_validation
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.contrib.sites.shortcuts import get_current_site
from django.core import exceptions, validators
from django.urls import NoReverseMatch, reverse
from django.utils.safestring import mark_safe
Expand Down Expand Up @@ -598,7 +597,6 @@ def save(self, request, **kwargs):
def _send_unknown_account_mail(self, request, email):
signup_url = build_absolute_uri(request, reverse("account_signup"))
context = {
"current_site": get_current_site(request),
"email": email,
"request": request,
"signup_url": signup_url,
Expand All @@ -624,7 +622,6 @@ def _send_password_reset_mail(self, request, email, users, **kwargs):
url = build_absolute_uri(request, path)

context = {
"current_site": get_current_site(request),
"user": user,
"password_reset_url": url,
"uid": uid,
Expand Down

0 comments on commit 0c99d5f

Please sign in to comment.