Skip to content

Commit

Permalink
Add email body_html template (django-otp#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
eugen1j committed Jan 2, 2023
1 parent ac02073 commit c3fa634
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/django_otp/plugins/otp_email/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class OTPEmailSettings:
'OTP_EMAIL_SUBJECT': 'OTP token',
'OTP_EMAIL_BODY_TEMPLATE': None,
'OTP_EMAIL_BODY_TEMPLATE_PATH': 'otp/email/token.txt',
'OTP_EMAIL_BODY_HTML_TEMPLATE': None,
'OTP_EMAIL_BODY_HTML_TEMPLATE_PATH': None,
'OTP_EMAIL_TOKEN_VALIDITY': 300,
'OTP_EMAIL_THROTTLE_FACTOR': 1,
}
Expand Down
10 changes: 9 additions & 1 deletion src/django_otp/plugins/otp_email/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,18 @@ def generate_challenge(self, extra_context=None):
else:
body = get_template(settings.OTP_EMAIL_BODY_TEMPLATE_PATH).render(context)

if settings.OTP_EMAIL_BODY_HTML_TEMPLATE:
body_html = Template(settings.OTP_EMAIL_BODY_HTML_TEMPLATE).render(Context(context))
elif settings.OTP_EMAIL_BODY_HTML_TEMPLATE_PATH:
body_html = get_template(settings.OTP_EMAIL_BODY_HTML_TEMPLATE_PATH).render(context)
else:
body_html = None

send_mail(settings.OTP_EMAIL_SUBJECT,
body,
settings.OTP_EMAIL_SENDER,
[self.email or self.user.email])
[self.email or self.user.email],
html_message=body_html)

message = "sent by email"

Expand Down

0 comments on commit c3fa634

Please sign in to comment.