Skip to content

Commit

Permalink
💥 Re-add OPEN-related outbound email templating code
Browse files Browse the repository at this point in the history
FLEX-106
  • Loading branch information
Justin Belanger committed Nov 10, 2023
1 parent 8c592dc commit 596715f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
15 changes: 12 additions & 3 deletions seed/landing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,19 @@ def password_set(request, uidb64=None, token=None):


def password_reset(request):
return auth.views.PasswordResetView.as_view(template_name='landing/password_reset.html')(
request,
extra_context = {
'domain': request.get_host(),
'protocol': settings.PROTOCOL,
'STATIC_URL': settings.STATIC_URL
}
return auth.views.PasswordResetView.as_view(
template_name='landing/password_reset.html',
subject_template_name='landing/password_reset_subject.txt',
email_template_name='landing/password_reset_email.html',
email_template_name='landing/password_reset_email.txt',
extra_email_context=extra_context,
html_email_template_name='landing/password_reset_email.html'
)(
request,
post_reset_redirect=reverse('landing:password_reset_done'),
from_email=settings.PASSWORD_RESET_EMAIL,
)
Expand Down
47 changes: 33 additions & 14 deletions seed/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,24 @@ def invite_new_user_to_seed(domain, email_address, token, user_pk, first_name):
'domain': domain,
'protocol': settings.PROTOCOL,
'first_name': first_name,
'signup_url': signup_url
'signup_url': signup_url,
'STATIC_URL': settings.STATIC_URL
}

subject = 'New SEED account'
email_body = loader.render_to_string(
'seed/account_create_email.txt',
context
)
html_email_body = loader.render_to_string(
'seed/account_create_email.html',
context
)
send_mail(subject, email_body, settings.SERVER_EMAIL, [email_address])
send_mail(subject, email_body, settings.SERVER_EMAIL, [email_address], html_message=html_email_body)
try:
bcc_address = settings.SEED_ACCOUNT_CREATION_BCC
new_subject = "{} ({})".format(subject, email_address)
send_mail(new_subject, email_body, settings.SERVER_EMAIL, [bcc_address])
send_mail(new_subject, email_body, settings.SERVER_EMAIL, [bcc_address], html_message=html_email_body)
except AttributeError:
pass

Expand All @@ -106,21 +111,30 @@ def invite_to_seed(domain, email_address, token, organization, user_pk, first_na
})
}))

content = Template(organization.new_user_email_content).render(Context({
context = {
'email': email_address,
'domain': domain,
'protocol': settings.PROTOCOL,
'first_name': first_name,
'sign_up_link': sign_up_url
}))
'signup_url': sign_up_url,
'STATIC_URL': settings.STATIC_URL
}

body = Template("{{content}}\n\n{{signature}}").render(Context({
'content': content,
'signature': organization.new_user_email_signature
}))
subject = 'New SEED account'
email_body = loader.render_to_string(
'seed/account_create_email.txt',
context
)
html_email_body = loader.render_to_string(
'seed/account_create_email.html',
context
)

send_mail(organization.new_user_email_subject, body, organization.new_user_email_from, [email_address])
send_mail(subject, email_body, settings.SERVER_EMAIL, [email_address], html_message=html_email_body)
try:
bcc_address = settings.SEED_ACCOUNT_CREATION_BCC
new_subject = "{} ({})".format(organization.new_user_email_subject, email_address)
send_mail(new_subject, body, organization.new_user_email_from, [bcc_address])
send_mail(new_subject, email_body, settings.SERVER_EMAIL, [bcc_address], html_message=html_email_body)
except AttributeError:
pass

Expand All @@ -144,18 +158,23 @@ def invite_to_organization(domain, new_user, requested_by, new_org):
'protocol': settings.PROTOCOL,
'new_org': new_org,
'requested_by': requested_by,
'STATIC_URL': settings.STATIC_URL
}

subject = 'Your SEED account has been added to an organization'
email_body = loader.render_to_string(
'seed/account_org_added.txt',
context
)
html_email_body = loader.render_to_string(
'seed/account_org_added.html',
context
)
send_mail(subject, email_body, settings.SERVER_EMAIL, [new_user.email])
send_mail(subject, email_body, settings.SERVER_EMAIL, [new_user.email], html_message=html_email_body)
try:
bcc_address = settings.SEED_ACCOUNT_CREATION_BCC
new_subject = "{} ({})".format(subject, new_user.email)
send_mail(new_subject, email_body, settings.SERVER_EMAIL, [bcc_address])
send_mail(new_subject, email_body, settings.SERVER_EMAIL, [bcc_address], html_message=html_email_body)
except AttributeError:
pass

Expand Down

0 comments on commit 596715f

Please sign in to comment.