Skip to content

Commit

Permalink
feat: Customizable email subjects.
Browse files Browse the repository at this point in the history
Added new settings for adjusting the subject lines of the emails sent by
the library.

Closes #96
  • Loading branch information
cdriehuys committed Dec 29, 2021
1 parent 1659769 commit c2bf548
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Expand Up @@ -28,6 +28,7 @@

// Set *default* container specific settings.json values on container create.
"settings": {
"editor.formatOnSave": true,
"terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": "/usr/local/bin/python",
"python.linting.enabled": true,
Expand All @@ -40,7 +41,7 @@
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
},

// Add the IDs of extensions you want installed when the container is created.
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.rst
@@ -1,6 +1,12 @@
Changelog
=========

In Development
--------------

Features
* :issue:`96`: Ability to customize email subjects.

v3.0.3
------

Expand Down
17 changes: 17 additions & 0 deletions docs/configuration.rst
Expand Up @@ -60,6 +60,23 @@ deleted by the ``cleanemailconfirmations`` command. See
:ref:`clean-email-confirmations` for more information.


``EMAIL_SUBJECT_DUPLICATE``
---------------------------

Default: ``Registration Attempt``

The subject line to use for emails notifying users of a registration attempt
for an email address that has already been registered.

``EMAIL_SUBJECT_VERFICATION``
-----------------------------

Default: ``Please Verify Your Email Address``

The subject line to use for emails containing a verification token for a
particular address.


.. _email-verification-password-required:

``EMAIL_VERIFICATION_PASSWORD_REQUIRED``
Expand Down
21 changes: 21 additions & 0 deletions rest_email_auth/app_settings.py
Expand Up @@ -7,6 +7,8 @@

import sys

from django.utils.translation import ugettext_lazy as _


class AppSettings(object):
def __init__(self):
Expand Down Expand Up @@ -67,6 +69,25 @@ def CONFIRMATION_SAVE_PERIOD(self):
"CONFIRMATION_SAVE_PERIOD", datetime.timedelta(days=7)
)

@property
def EMAIL_SUBJECT_DUPLICATE(self):
"""
The subject to use for emails notifying users of a duplicate
registration attempt.
"""
return self._setting(
"EMAIL_SUBJECT_DUPLICATE", _("Registration Attempt")
)

@property
def EMAIL_SUBJECT_VERIFICATION(self):
"""
The subject to use for emails containing verification tokens.
"""
return self._setting(
"EMAIL_SUBJECT_VERIFICATION", _("Please Verify Your Email Address")
)

@property
def EMAIL_VERIFICATION_PASSWORD_REQUIRED(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions rest_email_auth/models.py
Expand Up @@ -93,7 +93,7 @@ def send_duplicate_notification(self):
email_utils.send_email(
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=[self.email],
subject=_("Registration Attempt"),
subject=app_settings.EMAIL_SUBJECT_DUPLICATE,
template_name=app_settings.PATH_TO_DUPLICATE_EMAIL_TEMPLATE,
)

Expand Down Expand Up @@ -186,7 +186,7 @@ def send(self):
context=context,
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=[self.email.email],
subject=_("Please Verify Your Email Address"),
subject=app_settings.EMAIL_SUBJECT_VERIFICATION,
template_name=app_settings.PATH_TO_VERIFY_EMAIL_TEMPLATE,
)

Expand Down

0 comments on commit c2bf548

Please sign in to comment.